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
.- Since:
- 2.0
- Author:
- Oliver Gierke, Thomas Darimont, Christoph Strobl, Mark Paluch, Xeno Amess, Johannes Englmeier
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Value object holding the actualCustomConversions.StoreConversions
and customconverters
configured for registration.protected static class
Value class tying together aCustomConversions.ConverterRegistration
and itsorigin
to allow fine grained registration based on store supported types.static class
Value type to capture store-specific extensions to theCustomConversions
. -
Constructor Summary
ConstructorDescriptionCustomConversions
(CustomConversions.ConverterConfiguration converterConfiguration) CustomConversions
(CustomConversions.StoreConversions storeConversions, Collection<?> converters) Creates a newCustomConversions
instance registering all given user defined converters and selectingconverters
fromCustomConversions.StoreConversions
depending onstore simple types
only considering those that either convert to/from a store supported type. -
Method Summary
Modifier 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.Gets a reference to the configuredPropertyValueConversions
if property value conversions are supported by the underlying data store.Returns the underlyingSimpleTypeHolder
.boolean
hasCustomReadTarget
(Class<?> sourceType, Class<?> targetType) Returns whether we have a custom conversion registered to read the given source into the given target type.boolean
hasCustomWriteTarget
(Class<?> sourceType) Returns whether we have a custom conversion registered to readsourceType
into a native type.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.boolean
hasValueConverter
(PersistentProperty<?> property) Determines whether the given, requiredproperty
has a value-specific converter registered.boolean
isSimpleType
(Class<?> type) Returns whether the given type is considered to be simple.void
registerConvertersIn
(org.springframework.core.convert.converter.ConverterRegistry conversionService) Populates the givenGenericConversionService
with the converters registered.
-
Constructor Details
-
CustomConversions
- Parameters:
converterConfiguration
- theCustomConversions.ConverterConfiguration
to apply.- Since:
- 2.3
-
CustomConversions
public CustomConversions(@NonNull CustomConversions.StoreConversions storeConversions, @NonNull Collection<?> converters) Creates a newCustomConversions
instance registering all given user defined converters and selectingconverters
fromCustomConversions.StoreConversions
depending onstore simple types
only considering those that either convert to/from a store supported type.- Parameters:
storeConversions
- must not be null.converters
- must not be null.
-
-
Method Details
-
getSimpleTypeHolder
Returns the underlyingSimpleTypeHolder
.- Returns:
- the underlying
SimpleTypeHolder
. - See Also:
-
hasValueConverter
Determines whether the given, requiredproperty
has a value-specific converter registered. Returns false if noPropertyValueConversions
have been configured for the underlying store.This method protects against null when not
PropertyValueConversions
have been configured for the underlying data store, and is a shortcut for:customConversions.getPropertyValueConversions().hasValueConverter(property);
- Parameters:
property
-PersistentProperty
to evaluate; must not be null.- Returns:
- a boolean value indicating whether
PropertyValueConverter
has been configured and registered for theproperty
. - See Also:
-
isSimpleType
Returns whether the given type is considered to be simple. That means it's either a general simple type or we have a writingConverter
registered for a particular type. -
registerConvertersIn
public void registerConvertersIn(@NonNull org.springframework.core.convert.converter.ConverterRegistry conversionService) Populates the givenGenericConversionService
with the converters registered.- Parameters:
conversionService
-ConverterRegistry
to populate; must not be null.- See Also:
-
ConverterRegistry
-
getPropertyValueConversions
Gets a reference to the configuredPropertyValueConversions
if 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:
-
getCustomWriteTarget
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:
- 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
public Optional<Class<?>> getCustomWriteTarget(@NonNull Class<?> sourceType, @NonNull 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. IfrequestedTargetType
is null we will simply return the first target type matching or null if no conversion can be found.- Parameters:
sourceType
- must not be nullrequestedTargetType
- must not be null.- Returns:
- the target type we can read an inject of the given source type to.
-
hasCustomWriteTarget
Returns whether we have a custom conversion registered to readsourceType
into 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
sourceType
into a native type.
-
hasCustomWriteTarget
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:
- 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.
-
hasCustomReadTarget
Returns whether we have a custom conversion registered to read the given source into the given target type.- Parameters:
sourceType
- must not be nulltargetType
- must not be null- Returns:
- whether we have a custom conversion registered to read the given source into the given target type.
-