接口 ConversionService

所有已知子接口:
ConfigurableConversionService
所有已知实现类:
DefaultConversionService, GenericConversionService

public interface ConversionService
A service interface for type conversion. This is the entry point into the convert system. Call convert(Object, Class) to perform a thread-safe type conversion using this system.
从以下版本开始:
3.0 2021/3/19 20:59
作者:
Keith Donald, Phillip Webb, Harry Yang
  • 方法详细资料

    • getConverter

      @Nullable default GenericConverter getConverter(Class<?> sourceType, TypeDescriptor targetType)
      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 from
      targetType - the target type to convert to
      返回:
      the generic converter that will perform the conversion, or null if no suitable converter was found
    • getConverter

      @Nullable default GenericConverter getConverter(Object sourceObject, TypeDescriptor targetType)
      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 from
      targetType - the target type to convert to
      返回:
      the generic converter that will perform the conversion, or null if no suitable converter was found
    • getConverter

      @Nullable default GenericConverter getConverter(Object sourceObject, Class<?> targetType)
      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 from
      targetType - the target type to convert to
      返回:
      the generic converter that will perform the conversion, or null if no suitable converter was found
    • getConverter

      @Nullable GenericConverter getConverter(TypeDescriptor sourceType, TypeDescriptor targetType)
      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 from
      targetType - the target type to convert to
      返回:
      the generic converter that will perform the conversion, or null if no suitable converter was found
    • getConverter

      @Nullable default GenericConverter getConverter(Class<?> sourceType, Class<?> targetType)
      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 from
      targetType - the target type to convert to
      返回:
      the generic converter that will perform the conversion, or null if no suitable converter was found
    • canConvert

      boolean canConvert(@Nullable Class<?> sourceType, Class<?> targetType)
      Return true if objects of sourceType can be converted to the targetType.

      If this method returns true, it means convert(Object, Class) is capable of converting an instance of sourceType to targetType.

      Special note on collections, arrays, and maps types: For conversion between collection, array, and map types, this method will return true even though a convert invocation may still generate a ConversionException if 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 be null if source is null)
      targetType - the target type to convert to (required)
      返回:
      true if a conversion can be performed, false if not
      抛出:
      IllegalArgumentException - if targetType is null
    • canConvert

      boolean canConvert(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType)
      Return true if objects of sourceType can be converted to the targetType. 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 means convert(Object, TypeDescriptor, TypeDescriptor) is capable of converting an instance of sourceType to targetType.

      Special note on collections, arrays, and maps types: For conversion between collection, array, and map types, this method will return true even though a convert invocation may still generate a ConversionException if 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 be null if source is null)
      targetType - context about the target type to convert to (required)
      返回:
      true if a conversion can be performed between the source and target types, false if not
      抛出:
      IllegalArgumentException - if targetType is null
    • convert

      @Nullable <T> T convert(@Nullable Object source, Class<T> targetType)
      Convert the given source to the specified targetType.
      参数:
      source - the source object to convert (may be null)
      targetType - the target type to convert to (required)
      返回:
      the converted object, an instance of targetType
      抛出:
      ConversionException - if a conversion exception occurred
      IllegalArgumentException - if targetType is null
    • convert

      @Nullable <T> T convert(@Nullable Object source, TypeDescriptor targetType)
      Convert the given source to the specified targetType.
      参数:
      source - the source object to convert (may be null)
      targetType - the target type to convert to (required)
      返回:
      the converted object, an instance of targetType
      抛出:
      ConversionException - if a conversion exception occurred
      IllegalArgumentException - if targetType is null
    • convert

      @Nullable Object convert(@Nullable Object source, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType)
      Convert the given source to the specified targetType. 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 be null)
      sourceType - context about the source type to convert from (may be null if source is null)
      targetType - context about the target type to convert to (required)
      返回:
      the converted object, an instance of targetType
      抛出:
      ConversionException - if a conversion exception occurred
      IllegalArgumentException - if targetType is null, or sourceType is null but source is not null