public class StandardTypeConverter extends java.lang.Object implements TypeConverter
TypeConverter
interface,
delegating to a core Spring ConversionService
.ConversionService
Modifier and Type | Field and Description |
---|---|
private ConversionService |
conversionService |
private static ConversionService |
defaultConversionService |
Constructor and Description |
---|
StandardTypeConverter()
Create a StandardTypeConverter for the default ConversionService.
|
StandardTypeConverter(ConversionService conversionService)
Create a StandardTypeConverter for the given ConversionService.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canConvert(TypeDescriptor sourceType,
TypeDescriptor targetType)
Return
true if the type converter can convert the specified type
to the desired target type. |
java.lang.Object |
convertValue(java.lang.Object value,
TypeDescriptor sourceType,
TypeDescriptor targetType)
Convert (or coerce) a value from one type to another, for example from a
boolean to a String . |
private static ConversionService defaultConversionService
private final ConversionService conversionService
public StandardTypeConverter()
public StandardTypeConverter(ConversionService conversionService)
conversionService
- the ConversionService to delegate topublic boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType)
TypeConverter
true
if the type converter can convert the specified type
to the desired target type.canConvert
in interface TypeConverter
sourceType
- a type descriptor that describes the source typetargetType
- a type descriptor that describes the requested result typetrue
if that conversion can be performedpublic java.lang.Object convertValue(java.lang.Object value, TypeDescriptor sourceType, TypeDescriptor targetType)
TypeConverter
boolean
to a String
.
The TypeDescriptor
parameters enable support for typed collections:
A caller may prefer a List<Integer>
, for example, rather than
simply any List
.
convertValue
in interface TypeConverter
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