接口 ConversionService
- 所有已知子接口:
ConfigurableConversionService
convert(Object, Class) to perform a thread-safe type conversion using this system.- 从以下版本开始:
- 3.0
- 作者:
- Keith Donald, Phillip Webb, TODAY 2021/3/19 20:59
-
方法概要
修饰符和类型方法说明booleancanConvert(TypeDescriptor sourceType, TypeDescriptor targetType) Returntrueif objects ofsourceTypecan be converted to thetargetType.booleancanConvert(Class<?> sourceType, Class<?> targetType) Returntrueif objects ofsourceTypecan be converted to thetargetType.<T> Tconvert(Object source, TypeDescriptor targetType) Convert the givensourceto the specifiedtargetType.convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) Convert the givensourceto the specifiedtargetType.<T> TConvert the givensourceto the specifiedtargetType.getConverter(TypeDescriptor sourceType, TypeDescriptor targetType) Hook method to lookup the converter for a given sourceType/targetType pair.default GenericConvertergetConverter(Class<?> sourceType, TypeDescriptor targetType) Hook method to lookup the converter for a given sourceType/targetType pair.default GenericConvertergetConverter(Class<?> sourceType, Class<?> targetType) Hook method to lookup the converter for a given sourceType/targetType pair.default GenericConvertergetConverter(Object sourceObject, TypeDescriptor targetType) Hook method to lookup the converter for a given sourceType/targetType pair.default GenericConvertergetConverter(Object sourceObject, Class<?> targetType) Hook method to lookup the converter for a given sourceType/targetType pair.
-
方法详细资料
-
getConverter
Hook method to lookup the converter for a given sourceType/targetType pair. First queries this ConversionService's converter cache. On a cache miss, then performs an exhaustive search for a matching converter. If no converter matches, returns the default converter.- 参数:
sourceType- the source type to convert fromtargetType- the target type to convert to- 返回:
- the generic converter that will perform the conversion,
or
nullif no suitable converter was found
-
getConverter
Hook method to lookup the converter for a given sourceType/targetType pair. First queries this ConversionService's converter cache. On a cache miss, then performs an exhaustive search for a matching converter. If no converter matches, returns the default converter.- 参数:
sourceObject- the source to convert fromtargetType- the target type to convert to- 返回:
- the generic converter that will perform the conversion,
or
nullif no suitable converter was found
-
getConverter
Hook method to lookup the converter for a given sourceType/targetType pair. First queries this ConversionService's converter cache. On a cache miss, then performs an exhaustive search for a matching converter. If no converter matches, returns the default converter.- 参数:
sourceObject- the source to convert fromtargetType- the target type to convert to- 返回:
- the generic converter that will perform the conversion,
or
nullif no suitable converter was found
-
getConverter
Hook method to lookup the converter for a given sourceType/targetType pair. First queries this ConversionService's converter cache. On a cache miss, then performs an exhaustive search for a matching converter. If no converter matches, returns the default converter.- 参数:
sourceType- the source type to convert fromtargetType- the target type to convert to- 返回:
- the generic converter that will perform the conversion,
or
nullif no suitable converter was found
-
getConverter
Hook method to lookup the converter for a given sourceType/targetType pair. First queries this ConversionService's converter cache. On a cache miss, then performs an exhaustive search for a matching converter. If no converter matches, returns the default converter.- 参数:
sourceType- the source type to convert fromtargetType- the target type to convert to- 返回:
- the generic converter that will perform the conversion,
or
nullif no suitable converter was found
-
canConvert
Returntrueif objects ofsourceTypecan be converted to thetargetType.If this method returns
true, it meansconvert(Object, Class)is capable of converting an instance ofsourceTypetotargetType.Special note on collections, arrays, and maps types: For conversion between collection, array, and map types, this method will return
trueeven though a convert invocation may still generate aConversionExceptionif the underlying elements are not convertible. Callers are expected to handle this exceptional case when working with collections and maps.- 参数:
sourceType- the source type to convert from (may benullif source isnull)targetType- the target type to convert to (required)- 返回:
trueif a conversion can be performed,falseif not- 抛出:
IllegalArgumentException- iftargetTypeisnull
-
canConvert
Returntrueif objects ofsourceTypecan be converted to thetargetType. The TypeDescriptors provide additional context about the source and target locations where conversion would occur, often object fields or property locations.If this method returns
true, it meansconvert(Object, TypeDescriptor, TypeDescriptor)is capable of converting an instance ofsourceTypetotargetType.Special note on collections, arrays, and maps types: For conversion between collection, array, and map types, this method will return
trueeven though a convert invocation may still generate aConversionExceptionif the underlying elements are not convertible. Callers are expected to handle this exceptional case when working with collections and maps.- 参数:
sourceType- context about the source type to convert from (may benullif source isnull)targetType- context about the target type to convert to (required)- 返回:
trueif a conversion can be performed between the source and target types,falseif not- 抛出:
IllegalArgumentException- iftargetTypeisnull
-
convert
Convert the givensourceto the specifiedtargetType.- 参数:
source- the source object to convert (may benull)targetType- the target type to convert to (required)- 返回:
- the converted object, an instance of targetType
- 抛出:
ConversionException- if a conversion exception occurredIllegalArgumentException- if targetType isnull
-
convert
Convert the givensourceto the specifiedtargetType.- 参数:
source- the source object to convert (may benull)targetType- the target type to convert to (required)- 返回:
- the converted object, an instance of targetType
- 抛出:
ConversionException- if a conversion exception occurredIllegalArgumentException- if targetType isnull
-
convert
@Nullable Object convert(@Nullable Object source, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType) Convert the givensourceto the specifiedtargetType. The TypeDescriptors provide additional context about the source and target locations where conversion will occur, often object fields or property locations.- 参数:
source- the source object to convert (may benull)sourceType- context about the source type to convert from (may benullif source isnull)targetType- context about the target type to convert to (required)- 返回:
- the converted object, an instance of
targetType - 抛出:
ConversionException- if a conversion exception occurredIllegalArgumentException- if targetType isnull, orsourceTypeisnullbut source is notnull
-