类 ObjectToObjectConverter

java.lang.Object
cn.taketoday.core.conversion.support.ObjectToObjectConverter
所有已实现的接口:
ConditionalConverter, ConditionalGenericConverter, GenericConverter

final class ObjectToObjectConverter extends Object implements ConditionalGenericConverter
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

  1. Invoke a non-static to[targetType.simpleName]() method on the source object that has a return type equal to targetType, if such a method exists. For example, org.example.Bar Foo#toBar() is a method that follows this convention.
  2. Otherwise invoke a static valueOf(sourceType) or Java 8 style static of(sourceType) or from(sourceType) method on the targetType, if such a method exists.
  3. Otherwise invoke a constructor on the targetType that accepts a single sourceType argument, if such a constructor exists.
  4. 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
另请参阅:
  • 字段详细资料

  • 构造器详细资料

    • ObjectToObjectConverter

      ObjectToObjectConverter()
  • 方法详细资料

    • getConvertibleTypes

      public Set<GenericConverter.ConvertiblePair> getConvertibleTypes()
      从接口复制的说明: GenericConverter
      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 return null to indicate all source-to-target pairs should be considered.

      指定者:
      getConvertibleTypes 在接口中 GenericConverter
    • matches

      public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType)
      从接口复制的说明: ConditionalConverter
      Should the conversion from sourceType to targetType currently under consideration be selected?
      指定者:
      matches 在接口中 ConditionalConverter
      参数:
      sourceType - the type descriptor of the field we are converting from
      targetType - 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)
      从接口复制的说明: GenericConverter
      Convert the source object to the targetType described by the TypeDescriptor.
      指定者:
      convert 在接口中 GenericConverter
      参数:
      source - the source object to convert (may be null)
      sourceType - the type descriptor of the field we are converting from
      targetType - the type descriptor of the field we are converting to
      返回:
      the converted object
    • hasConversionMethodOrConstructor

      static boolean hasConversionMethodOrConstructor(Class<?> targetClass, Class<?> sourceClass)
    • getValidatedExecutable

      @Nullable private static Executable getValidatedExecutable(Class<?> targetClass, Class<?> sourceClass)
    • isApplicable

      private static boolean isApplicable(Executable executable, Class<?> sourceClass)
    • determineToMethod

      @Nullable private static Method determineToMethod(Class<?> targetClass, Class<?> sourceClass)
    • determineFactoryMethod

      @Nullable private static Method determineFactoryMethod(Class<?> targetClass, Class<?> sourceClass)
    • areRelatedTypes

      private static boolean areRelatedTypes(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).
      另请参阅:
    • determineFactoryConstructor

      @Nullable private static Constructor<?> determineFactoryConstructor(Class<?> targetClass, Class<?> sourceClass)