final class ObjectToObjectConverter extends java.lang.Object implements ConditionalGenericConverter
Calls a static valueOf(sourceType)
or Java 8 style of|from(sourceType)
method on the target type to perform the conversion, if such a method exists. Otherwise,
it checks for a to[targetType.simpleName]
method on the source type calls
the target type's constructor that accepts a single sourceType
argument, if such
a constructor exists. If neither strategy works, it throws a ConversionFailedException.
GenericConverter.ConvertiblePair
Constructor and Description |
---|
ObjectToObjectConverter() |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
convert(java.lang.Object source,
TypeDescriptor sourceType,
TypeDescriptor targetType)
Convert the source to the targetType described by the TypeDescriptor.
|
java.util.Set<GenericConverter.ConvertiblePair> |
getConvertibleTypes()
Return the source and target types which this converter can convert between.
|
(package private) static java.lang.reflect.Method |
getOfMethod(java.lang.Class<?> targetClass,
java.lang.Class<?> sourceClass) |
private static java.lang.reflect.Method |
getToMethod(java.lang.Class<?> targetClass,
java.lang.Class<?> sourceClass) |
private static boolean |
hasToMethodOrOfMethodOrConstructor(java.lang.Class<?> targetClass,
java.lang.Class<?> sourceClass) |
boolean |
matches(TypeDescriptor sourceType,
TypeDescriptor targetType)
Should the conversion from
sourceType to targetType currently under
consideration be selected? |
public java.util.Set<GenericConverter.ConvertiblePair> getConvertibleTypes()
GenericConverter
For conditional
converters this method may return
null
to indicate all source-to-target pairs should be considered. *
getConvertibleTypes
in interface GenericConverter
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType)
ConditionalConverter
sourceType
to targetType
currently under
consideration be selected?matches
in interface ConditionalConverter
sourceType
- the type descriptor of the field we are converting fromtargetType
- the type descriptor of the field we are converting topublic java.lang.Object convert(java.lang.Object source, TypeDescriptor sourceType, TypeDescriptor targetType)
GenericConverter
convert
in interface GenericConverter
source
- the source object to convert (may be null)sourceType
- the type descriptor of the field we are converting fromtargetType
- the type descriptor of the field we are converting toprivate static boolean hasToMethodOrOfMethodOrConstructor(java.lang.Class<?> targetClass, java.lang.Class<?> sourceClass)
private static java.lang.reflect.Method getToMethod(java.lang.Class<?> targetClass, java.lang.Class<?> sourceClass)
static java.lang.reflect.Method getOfMethod(java.lang.Class<?> targetClass, java.lang.Class<?> sourceClass)