Class ConvertingPropertyAccessor<T>
java.lang.Object
org.springframework.data.mapping.model.ConvertingPropertyAccessor<T>
- All Implemented Interfaces:
PersistentPropertyAccessor<T>,PersistentPropertyPathAccessor<T>
PersistentPropertyAccessor that potentially converts the value handed to
setProperty(PersistentProperty, Object) to the type of the PersistentProperty using a
ConversionService. Exposes getProperty(PersistentProperty, Class) to allow obtaining the value of a
property in a type the ConversionService can convert the raw type to.- Author:
- Oliver Gierke, Mark Paluch
-
Constructor Summary
ConstructorsConstructorDescriptionConvertingPropertyAccessor(PersistentPropertyAccessor<T> accessor, ConversionService conversionService) Creates a newConvertingPropertyAccessorfor the given delegatePersistentPropertyAccessorandConversionService. -
Method Summary
Modifier and TypeMethodDescriptiongetBean()Returns the underlying bean.getProperty(PersistentProperty<?> property) Returns the value of the givenPersistentPropertyof the underlying bean instance.<S> SgetProperty(PersistentProperty<?> property, Class<S> targetType) Returns the value of the givenPersistentPropertyconverted to the given type.getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path) Return the value pointed to by the givenPersistentPropertyPath.getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, AccessOptions.GetOptions options) Return the value pointed to by the givenPersistentPropertyPath.protected <S> SgetTypedProperty(PersistentProperty<?> property, Class<S> type) Returns the value of the givenPersistentPropertypotentially applying type conversion to the given target type.voidsetProperty(PersistentProperty<?> property, Object value) Sets the givenPersistentPropertyto the given value.voidsetProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, Object value) Sets the given value for thePersistentPropertypointed to by the givenPersistentPropertyPath.voidsetProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, Object value, AccessOptions.SetOptions options) Sets the given value for thePersistentPropertypointed to by the givenPersistentPropertyPathconsidering the givenAccessOptions.
-
Constructor Details
-
ConvertingPropertyAccessor
public ConvertingPropertyAccessor(PersistentPropertyAccessor<T> accessor, ConversionService conversionService) Creates a newConvertingPropertyAccessorfor the given delegatePersistentPropertyAccessorandConversionService.- Parameters:
accessor- must not be null.conversionService- must not be null.
-
-
Method Details
-
setProperty
Description copied from interface:PersistentPropertyAccessorSets the givenPersistentPropertyto the given value. Will do type conversion if aConversionServiceis configured.- Specified by:
setPropertyin interfacePersistentPropertyAccessor<T>- Parameters:
property- must not be null.value- can be null.
-
setProperty
public void setProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, @Nullable Object value) Description copied from interface:PersistentPropertyPathAccessorSets the given value for thePersistentPropertypointed to by the givenPersistentPropertyPath. The lookup of intermediate values must not yield null.- Specified by:
setPropertyin interfacePersistentPropertyPathAccessor<T>- Parameters:
path- must not be null or empty.value- can be null.- See Also:
-
getProperty
Returns the value of the givenPersistentPropertyconverted to the given type.- Parameters:
property- must not be null.targetType- must not be null.- Returns:
-
getTypedProperty
Returns the value of the givenPersistentPropertypotentially applying type conversion to the given target type. The default implementation will not attempt any conversion and reject a type mismatch with aMappingException.- Parameters:
property- will never be null.type- will never be null.- Returns:
- can be null.
-
getBean
Description copied from interface:PersistentPropertyAccessorReturns the underlying bean. The actual instance may change betweenPersistentPropertyAccessor.setProperty(PersistentProperty, Object)calls.- Specified by:
getBeanin interfacePersistentPropertyAccessor<T>- Returns:
- will never be null.
-
getProperty
Description copied from interface:PersistentPropertyAccessorReturns the value of the givenPersistentPropertyof the underlying bean instance.- Specified by:
getPropertyin interfacePersistentPropertyAccessor<T>- Parameters:
property- must not be null.- Returns:
- can be null.
-
getProperty
Description copied from interface:PersistentPropertyPathAccessorReturn the value pointed to by the givenPersistentPropertyPath. If the given path is empty, the wrapped bean is returned.- Specified by:
getPropertyin interfacePersistentPropertyPathAccessor<T>- Parameters:
path- must not be null.- Returns:
-
getProperty
@Nullable public Object getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, AccessOptions.GetOptions options) Description copied from interface:PersistentPropertyPathAccessorReturn the value pointed to by the givenPersistentPropertyPath. If the given path is empty, the wrapped bean is returned. On each path segment value lookup, the resulting value is post-processed depending on the givenAccessOptions.GetOptions.- Specified by:
getPropertyin interfacePersistentPropertyPathAccessor<T>- Parameters:
path- must not be null.options- must not be null.- Returns:
-
setProperty
public void setProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, @Nullable Object value, AccessOptions.SetOptions options) Description copied from interface:PersistentPropertyPathAccessorSets the given value for thePersistentPropertypointed to by the givenPersistentPropertyPathconsidering the givenAccessOptions.- Specified by:
setPropertyin interfacePersistentPropertyPathAccessor<T>- Parameters:
path- must not be null.value- must not be null.options- must not be null.
-