Class CustomConversions

java.lang.Object
org.springframework.data.convert.CustomConversions

public class CustomConversions extends Object
Value object to capture custom conversion. That is essentially a List of converters and some additional logic around them. The converters build up two sets of types which store-specific basic types can be converted into and from. These types will be considered simple ones (which means they neither need deeper inspection nor nested conversion. Thus, the CustomConversions also act as factory for SimpleTypeHolder .
Since:
2.0
Author:
Oliver Gierke, Thomas Darimont, Christoph Strobl, Mark Paluch, Xeno Amess
  • Constructor Details

  • Method Details

    • getSimpleTypeHolder

      public SimpleTypeHolder getSimpleTypeHolder()
      Returns the underlying SimpleTypeHolder.
      Returns:
    • isSimpleType

      public boolean isSimpleType(Class<?> type)
      Returns whether the given type is considered to be simple. That means it's either a general simple type or we have a writing Converter registered for a particular type.
      Parameters:
      type -
      Returns:
      See Also:
    • registerConvertersIn

      public void registerConvertersIn(ConverterRegistry conversionService)
      Populates the given GenericConversionService with the converters registered.
      Parameters:
      conversionService -
    • hasPropertyValueConverter

      public boolean hasPropertyValueConverter(PersistentProperty<?> property)
      Delegate check if a PropertyValueConverter for the given property is present via PropertyValueConversions.
      Parameters:
      property - must not be null.
      Returns:
      true if a specific PropertyValueConverter is available.
      Since:
      2.7
      See Also:
    • getPropertyValueConverter

      @Nullable public <DV, SV, C extends PersistentProperty<C>, VCC extends ValueConversionContext<C>> PropertyValueConverter<DV,SV,VCC> getPropertyValueConverter(C property)
      Delegate to obtain the PropertyValueConverter for the given property from PropertyValueConversions.
      Type Parameters:
      DV - domain-specific type
      SV - store-native type
      C - conversion context type
      Parameters:
      property - must not be null.
      Returns:
      the suitable PropertyValueConverter or null if none available.
      Since:
      2.7
      See Also:
    • getCustomWriteTarget

      public Optional<Class<?>> getCustomWriteTarget(Class<?> sourceType)
      Returns the target type to convert to in case we have a custom conversion registered to convert the given source type into a store native one.
      Parameters:
      sourceType - must not be null
      Returns:
    • getCustomWriteTarget

      public Optional<Class<?>> getCustomWriteTarget(Class<?> sourceType, Class<?> requestedTargetType)
      Returns the target type we can read an inject of the given source type to. The returned type might be a subclass of the given expected type though. If requestedTargetType is null we will simply return the first target type matching or null if no conversion can be found.
      Parameters:
      sourceType - must not be null
      requestedTargetType - must not be null.
      Returns:
    • hasCustomWriteTarget

      public boolean hasCustomWriteTarget(Class<?> sourceType)
      Returns whether we have a custom conversion registered to read sourceType into a native type. The returned type might be a subclass of the given expected type though.
      Parameters:
      sourceType - must not be null
      Returns:
    • hasCustomWriteTarget

      public boolean hasCustomWriteTarget(Class<?> sourceType, Class<?> targetType)
      Returns whether we have a custom conversion registered to read an object of the given source type into an object of the given native target type.
      Parameters:
      sourceType - must not be null.
      targetType - must not be null.
      Returns:
    • hasCustomReadTarget

      public boolean hasCustomReadTarget(Class<?> sourceType, Class<?> targetType)
      Returns whether we have a custom conversion registered to read the given source into the given target type.
      Parameters:
      sourceType - must not be null
      targetType - must not be null
      Returns: