Package org.springframework.data.convert
Class CustomConversions
java.lang.Object
org.springframework.data.convert.CustomConversions
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.
 Custom conversions supports the following converters:
- Converters built by ConverterBuilder
- GenericConverter
- ConverterFactory
- Converter
ConditionalConverter
 as custom conversions maintains a registry of convertible type pairs; We cannot determine convertible types based on
 ConditionalConverter#matches, instead, we require a converter to provide its convertible types either through
 the class declaration or GenericConverter#getConvertibleTypes.- Since:
- 2.0
- Author:
- Oliver Gierke, Thomas Darimont, Christoph Strobl, Mark Paluch, Xeno Amess, Johannes Englmeier
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected static classValue object holding the actualCustomConversions.StoreConversionsand customconvertersconfigured for registration.protected static classValue class tying together aCustomConversions.ConverterRegistrationand itsoriginto allow fine-grained registration based on store supported types.static classValue type to capture store-specific extensions to theCustomConversions.
- 
Constructor SummaryConstructorsConstructorDescriptionCustomConversions(CustomConversions.ConverterConfiguration converterConfiguration) CustomConversions(CustomConversions.StoreConversions storeConversions, Collection<?> converters) Creates a newCustomConversionsinstance registering all given user defined converters and selectingconvertersfromCustomConversions.StoreConversionsdepending onstore simple typesonly considering those that either convert to/from a store supported type.
- 
Method SummaryModifier and TypeMethodDescriptiongetCustomWriteTarget(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.getCustomWriteTarget(Class<?> sourceType, Class<?> requestedTargetType) Returns the target type we can read an inject of the given source type to.@Nullable PropertyValueConversionsGets a reference to the configuredPropertyValueConversionsif property value conversions are supported by the underlying data store.<DV,SV, P extends PersistentProperty<P>, VCC extends ValueConversionContext<P>> 
 PropertyValueConverter<DV,SV, VCC> getRequiredValueConverter(P property) Returns the requiredPropertyValueConverterfor the givenPersistentPropertyor throwsIllegalStateExceptionif no converter is available.Returns the underlyingSimpleTypeHolder.booleanhasCustomReadTarget(Class<?> sourceType, Class<?> targetType) Returns whether we have a custom conversion registered to read the given source into the given target type.booleanhasCustomWriteTarget(Class<?> sourceType) Returns whether we have a custom conversion registered to readsourceTypeinto a native type.booleanhasCustomWriteTarget(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.booleanhasValueConverter(PersistentProperty<?> property) Determines whether the given, requiredpropertyhas a value-specific converter registered.booleanisSimpleType(Class<?> type) Returns whether the given type is considered to be simple.voidregisterConvertersIn(ConverterRegistry conversionService) Populates the givenGenericConversionServicewith the converters registered.
- 
Constructor Details- 
CustomConversions- Parameters:
- converterConfiguration- the- CustomConversions.ConverterConfigurationto apply.
- Since:
- 2.3
 
- 
CustomConversionspublic CustomConversions(CustomConversions.StoreConversions storeConversions, Collection<?> converters) Creates a newCustomConversionsinstance registering all given user defined converters and selectingconvertersfromCustomConversions.StoreConversionsdepending onstore simple typesonly considering those that either convert to/from a store supported type.- Parameters:
- storeConversions- must not be null.
- converters- must not be null.
 
 
- 
- 
Method Details- 
getSimpleTypeHolderReturns the underlyingSimpleTypeHolder.- Returns:
- the underlying SimpleTypeHolder.
- See Also:
 
- 
hasValueConverterDetermines whether the given, requiredpropertyhas a value-specific converter registered. Returns false if noPropertyValueConversionshave been configured for the underlying store.This method protects against null when not PropertyValueConversionshave been configured for the underlying data store, and is a shortcut for:customConversions.getPropertyValueConversions().hasValueConverter(property);- Parameters:
- property-- PersistentPropertyto evaluate; must not be null.
- Returns:
- a boolean value indicating whether PropertyValueConverterhas been configured and registered for theproperty.
- See Also:
 
- 
getRequiredValueConverterpublic <DV,SV, PropertyValueConverter<DV,P extends PersistentProperty<P>, VCC extends ValueConversionContext<P>> SV, getRequiredValueConverterVCC> (P property) Returns the requiredPropertyValueConverterfor the givenPersistentPropertyor throwsIllegalStateExceptionif no converter is available. This is a convenience method forgetPropertyValueConversions().getValueConverter(…)enforcing non-null constraints.Prior to calling this method you should verify a converter is available using hasValueConverter(PersistentProperty).- Parameters:
- property-- PersistentPropertyto evaluate; must not be null.
- Returns:
- the required PropertyValueConverter
- Throws:
- IllegalStateException- if no converter is available.
- Since:
- 4.0
- See Also:
 
- 
isSimpleTypeReturns whether the given type is considered to be simple. That means it's either a general simple type or we have a writingConverterregistered for a particular type.
- 
registerConvertersInPopulates the givenGenericConversionServicewith the converters registered.- Parameters:
- conversionService-- ConverterRegistryto populate; must not be null.
- See Also:
 
- 
getPropertyValueConversionsGets a reference to the configuredPropertyValueConversionsif property value conversions are supported by the underlying data store.- Returns:
- a reference to the configured PropertyValueConversions; may be null if the underlying data store does not support property value conversions.
- See Also:
 
- 
getCustomWriteTargetReturns 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:
- 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.
 
- 
getCustomWriteTargetReturns 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. IfrequestedTargetTypeis 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:
- the target type we can read an inject of the given source type to.
 
- 
hasCustomWriteTargetReturns whether we have a custom conversion registered to readsourceTypeinto a native type. The returned type might be a subclass of the given expected type though.- Parameters:
- sourceType- must not be null
- Returns:
- whether we have a custom conversion registered to read sourceTypeinto a native type.
 
- 
hasCustomWriteTargetReturns 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:
- 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.
 
- 
hasCustomReadTargetReturns 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:
- whether we have a custom conversion registered to read the given source into the given target type.
 
 
-