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
Modifier and TypeMethodDescriptionboolean
canConvert
(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType) Returntrue
if the type converter can convert the specified type to the desired target type.convertValue
(@Nullable Object value, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType) Convert (or coerce) a value from one type to another, for example from aboolean
to aString
.
-
Method Details
-
canConvert
Returntrue
if the type converter can convert the specified type to the desired target type.- Parameters:
sourceType
- a type descriptor that describes the source typetargetType
- a type descriptor that describes the requested result type- Returns:
true
if that conversion can be performed
-
convertValue
@Nullable Object convertValue(@Nullable Object value, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType) Convert (or coerce) a value from one type to another, for example from aboolean
to aString
.The
TypeDescriptor
parameters enable support for typed collections: A caller may prefer aList<Integer>
, for example, rather than simply anyList
.- Parameters:
value
- the value to be convertedsourceType
- a type descriptor that supplies extra information about the source objecttargetType
- a type descriptor that supplies extra information about the requested result type- Returns:
- the converted value
- Throws:
EvaluationException
- if conversion failed or is not possible to begin with
-