org.springframework.expression
Interface TypeConverter

All Known Implementing Classes:
StandardTypeConverter

public interface TypeConverter

A type converter can convert values between different types encountered during expression evaluation. This is an SPI for the expression parser; see ConversionService for the primary user API to Spring's conversion facilities.

Since:
3.0
Author:
Andy Clement, Juergen Hoeller

Method Summary
 boolean canConvert(Class<?> sourceType, Class<?> targetType)
          Return true if the type converter can convert the specified type to the desired target type.
 Object convertValue(Object value, TypeDescriptor typeDescriptor)
          Convert (may coerce) a value from one type to another, for example from a boolean to a string.
 

Method Detail

canConvert

boolean canConvert(Class<?> sourceType,
                   Class<?> targetType)
Return true if the type converter can convert the specified type to the desired target type.

Parameters:
sourceType - the type to be converted from
targetType - the type to be converted to
Returns:
true if that conversion can be performed

convertValue

Object convertValue(Object value,
                    TypeDescriptor typeDescriptor)
                    throws EvaluationException
Convert (may coerce) a value from one type to another, for example from a boolean to a string. The typeDescriptor parameter enables support for typed collections - if the caller really wishes they can have a List for example, rather than simply a List.

Parameters:
value - the value to be converted
typeDescriptor - a type descriptor that supplies extra information about the requested result type
Returns:
the converted value
Throws:
EvaluationException - if conversion is not possible