类 ObjectToObjectConverter
java.lang.Object
cn.taketoday.core.conversion.support.ObjectToObjectConverter
Generic converter that uses conventions to convert a source object to a
targetType by delegating to a method on the source object or to
a static factory method or constructor on the targetType.
Conversion Algorithm
- Invoke a non-static
to[targetType.simpleName]()method on the source object that has a return type equal totargetType, if such a method exists. For example,org.example.Bar Foo#toBar()is a method that follows this convention. - Otherwise invoke a static
valueOf(sourceType)or Java 8 style staticof(sourceType)orfrom(sourceType)method on thetargetType, if such a method exists. - Otherwise invoke a constructor on the
targetTypethat accepts a singlesourceTypeargument, if such a constructor exists. - Otherwise throw a
ConversionFailedException.
Warning: this converter does not support the
Object.toString() or String.valueOf(Object) methods for converting
from a sourceType to java.lang.String. For toString()
support, use FallbackObjectToStringConverter instead.
- 从以下版本开始:
- 3.0
- 作者:
- Keith Donald, Juergen Hoeller, Sam Brannen
- 另请参阅:
-
嵌套类概要
从接口继承的嵌套类/接口 cn.taketoday.core.conversion.GenericConverter
GenericConverter.ConvertiblePair -
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明private static booleanareRelatedTypes(Class<?> type1, Class<?> type2) Determine if the two types reside in the same type hierarchy (i.e., type 1 is assignable to type 2 or vice versa).convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) Convert the source object to the targetType described by theTypeDescriptor.private static Constructor<?>determineFactoryConstructor(Class<?> targetClass, Class<?> sourceClass) private static MethoddetermineFactoryMethod(Class<?> targetClass, Class<?> sourceClass) private static MethoddetermineToMethod(Class<?> targetClass, Class<?> sourceClass) Return the source and target types that this converter can convert between.private static ExecutablegetValidatedExecutable(Class<?> targetClass, Class<?> sourceClass) (专用程序包) static booleanhasConversionMethodOrConstructor(Class<?> targetClass, Class<?> sourceClass) private static booleanisApplicable(Executable executable, Class<?> sourceClass) booleanmatches(TypeDescriptor sourceType, TypeDescriptor targetType) Should the conversion fromsourceTypetotargetTypecurrently under consideration be selected?
-
字段详细资料
-
conversionExecutableCache
-
-
构造器详细资料
-
ObjectToObjectConverter
ObjectToObjectConverter()
-
-
方法详细资料
-
getConvertibleTypes
从接口复制的说明:GenericConverterReturn the source and target types that this converter can convert between.Each entry is a convertible source-to-target type pair.
For
conditional convertersthis method may returnnullto indicate all source-to-target pairs should be considered.- 指定者:
getConvertibleTypes在接口中GenericConverter
-
matches
从接口复制的说明:ConditionalConverterShould the conversion fromsourceTypetotargetTypecurrently under consideration be selected?- 指定者:
matches在接口中ConditionalConverter- 参数:
sourceType- the type descriptor of the field we are converting fromtargetType- the type descriptor of the field we are converting to- 返回:
- true if conversion should be performed, false otherwise
-
convert
@Nullable public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) 从接口复制的说明:GenericConverterConvert the source object to the targetType described by theTypeDescriptor.- 指定者:
convert在接口中GenericConverter- 参数:
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
-
hasConversionMethodOrConstructor
-
getValidatedExecutable
@Nullable private static Executable getValidatedExecutable(Class<?> targetClass, Class<?> sourceClass) -
isApplicable
-
determineToMethod
-
determineFactoryMethod
-
areRelatedTypes
Determine if the two types reside in the same type hierarchy (i.e., type 1 is assignable to type 2 or vice versa). -
determineFactoryConstructor
@Nullable private static Constructor<?> determineFactoryConstructor(Class<?> targetClass, Class<?> sourceClass)
-