public interface

TypeConverter

org.springframework.expression.TypeConverter
Known Indirect Subclasses

Class Overview

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.

Summary

Public Methods
abstract boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType)
Return true if the type converter can convert the specified type to the desired target type.
abstract Object convertValue(Object value, TypeDescriptor sourceType, TypeDescriptor targetType)
Convert (may coerce) a value from one type to another, for example from a boolean to a string.

Public Methods

public abstract boolean canConvert (TypeDescriptor sourceType, TypeDescriptor targetType)

Return true if the type converter can convert the specified type to the desired target type.

Parameters
sourceType a type descriptor that describes the source type
targetType a type descriptor that describes the requested result type
Returns
  • true if that conversion can be performed

public abstract Object convertValue (Object value, TypeDescriptor sourceType, TypeDescriptor targetType)

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<Integer> for example, rather than simply a List.

Parameters
value the value to be converted
sourceType a type descriptor that supplies extra information about the source object
targetType a type descriptor that supplies extra information about the requested result type
Returns
  • the converted value
Throws
EvaluationException if conversion is not possible