接口 GenericConverter
- 所有已知子接口:
ConditionalGenericConverter
public interface GenericConverter
Generic converter interface for converting between two or more types.This is the most flexible of the Converter SPI interfaces, but also the most complex. It is flexible in that a GenericConverter may support converting between multiple source/target type pairs (see
getConvertibleTypes()
. In addition, GenericConverter implementations have access to source/targetfield context
during the type conversion process. This allows for resolving source and target field metadata such as annotations and generics information, which can be used to influence the conversion logic.This interface should generally not be used when the simpler
Converter
orConverterFactory
interface is sufficient.Implementations may additionally implement
ConditionalConverter
.- 从以下版本开始:
- 3.0
- 作者:
- Keith Donald, Juergen Hoeller
- 另请参阅:
TypeDescriptor
,Converter
,ConverterFactory
,ConditionalConverter
嵌套类概要
嵌套类 修饰符和类型 接口 说明 static class
GenericConverter.ConvertiblePair
Holder for a source-to-target class pair.
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 Object
convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType)
Convert the source object to the targetType described by theTypeDescriptor
.Set<GenericConverter.ConvertiblePair>
getConvertibleTypes()
Return the source and target types that this converter can convert between.
方法详细资料
getConvertibleTypes
Set<GenericConverter.ConvertiblePair> getConvertibleTypes()
Return the source and target types that this converter can convert between.Each entry is a convertible source-to-target type pair.
For
conditional converters
this method may returnnull
to indicate all source-to-target pairs should be considered.
convert
Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType)
Convert the source object to the targetType described by theTypeDescriptor
.- 参数:
source
- the source object to convert (may benull
)sourceType
- the type descriptor of the field we are converting fromtargetType
- the type descriptor of the field we are converting to- 返回:
- the converted object