Print
Type Converters

While MVEL supports a wide-range of conversion handlers, it may be necessary to extend this functionality to domain-specific types.

The ConversionHandler Interface.

Implementing a converter is relatively straight-forward and involves implementing two methods.

Converters in MVEL are type-to converters, meaning that each handler represents a target type. So each handler is expected to understand how to convert from specific types to the type represented by the handler. Consider the following:

This simple converter converts the imaginary type Bar to the imaginary type Foo.

In reality, actual converters are somewhat more complex, having the ability to convert from various different types. Consider how the Integer conversion handler is implemented in the MVEL default conversion package:

Registering Handlers

A conversion handler is registered with the org.mvel.DataConversion factory class using the static addConversionHandler method.

Powered by Atlassian Confluence