Package org.springframework.data.convert
Class PropertyValueConverterRegistrar<P extends PersistentProperty<P>>
java.lang.Object
org.springframework.data.convert.PropertyValueConverterRegistrar<P>
Configuration class used to register a
PropertyValueConverter with
a SimplePropertyValueConverterRegistry that can be used in PropertyValueConversions.
It is possible to register type safe converters via registerConverter(Class, Function)
registrar.registerConverter(Person.class, Person::getName) //
.writing(StringConverter::encrypt) //
.reading(StringConverter::decrypt);
- Since:
- 2.7
- Author:
- Christoph Strobl, Oliver Drotbohm
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classPropertyValueConverterRegistrar.ReadingConverterRegistrationBuilder<T,S, R, P extends PersistentProperty<P>> Helper class used to build a fluent API to register how to read a database value into a domain object property.static classPropertyValueConverterRegistrar.WritingConverterRegistrationBuilder<T,S, P extends PersistentProperty<P>> Helper class used to build up a fluent registration API starting with writing. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionObtain theSimplePropertyValueConverterRegistry.registerConverter(Class<?> type, String path, PropertyValueConverter<?, ?, ? extends ValueConversionContext<?>> converter) Register the givenconverterfor the given type and property identified by its name.registerConverter(Class<T> type, String propertyName, Class<S> propertyType) Starts a converter registration by pointing to a property of a domain type.registerConverter(Class<T> type, Function<T, S> property) Starts a converter registration by pointing to a property of a domain type.voidregisterConvertersIn(ValueConverterRegistry<P> target) Register collectedconverterswithin the givenregistry.
-
Constructor Details
-
PropertyValueConverterRegistrar
public PropertyValueConverterRegistrar()
-
-
Method Details
-
registerConverter
public <T,S> PropertyValueConverterRegistrar.WritingConverterRegistrationBuilder<T,S, registerConverterP> (Class<T> type, Function<T, S> property) Starts a converter registration by pointing to a property of a domain type.- Type Parameters:
T- the domain typeS- the property type- Parameters:
type- the domain type to obtain the property fromproperty- aFunctionto describe the property to be referenced. Usually a method handle to a getter.- Returns:
- will never be null.
-
registerConverter
public <T,S> PropertyValueConverterRegistrar.WritingConverterRegistrationBuilder<T,S, registerConverterP> (Class<T> type, String propertyName, Class<S> propertyType) Starts a converter registration by pointing to a property of a domain type.- Type Parameters:
T- the domain typeS- the property type- Parameters:
type- the domain type to obtain the property frompropertyName- aFunctionto describe the property to be referenced. Usually a method handle to a getter.- Returns:
- will never be null.
-
registerConverter
public PropertyValueConverterRegistrar<P> registerConverter(Class<?> type, String path, PropertyValueConverter<?, ?, ? extends ValueConversionContext<?>> converter) Register the givenconverterfor the given type and property identified by its name.- Parameters:
type- the domain type to obtain the property frompath- the property name.converter- theconverterto apply.- Returns:
- this.
-
registerConvertersIn
Register collectedconverterswithin the givenregistry.- Parameters:
target-ValueConverterRegistryfrom which to registerconverters; must not be null.- Throws:
IllegalArgumentException- if theValueConverterRegistryis null.- See Also:
-
buildRegistry
Obtain theSimplePropertyValueConverterRegistry.- Returns:
- new instance of
SimplePropertyValueConverterRegistry.
-