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
ConstructorDescriptionConvertingPropertyAccessor
(PersistentPropertyAccessor<T> accessor, ConversionService conversionService) Creates a newConvertingPropertyAccessor
for the given delegatePersistentPropertyAccessor
andConversionService
. -
Method Summary
Modifier and TypeMethodDescriptiongetBean()
Returns the underlying bean.getProperty
(PersistentProperty<?> property) Returns the value of the givenPersistentProperty
of the underlying bean instance.<S> S
getProperty
(PersistentProperty<?> property, Class<S> targetType) Returns the value of the givenPersistentProperty
converted 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> S
getTypedProperty
(PersistentProperty<?> property, Class<S> type) Returns the value of the givenPersistentProperty
potentially applying type conversion to the given target type.void
setProperty
(PersistentProperty<?> property, Object value) Sets the givenPersistentProperty
to the given value.void
setProperty
(PersistentPropertyPath<? extends PersistentProperty<?>> path, Object value) Sets the given value for thePersistentProperty
pointed to by the givenPersistentPropertyPath
.void
setProperty
(PersistentPropertyPath<? extends PersistentProperty<?>> path, Object value, AccessOptions.SetOptions options) Sets the given value for thePersistentProperty
pointed to by the givenPersistentPropertyPath
considering the givenAccessOptions
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.data.mapping.PersistentPropertyAccessor
getProperty
-
Constructor Details
-
ConvertingPropertyAccessor
public ConvertingPropertyAccessor(PersistentPropertyAccessor<T> accessor, ConversionService conversionService) Creates a newConvertingPropertyAccessor
for the given delegatePersistentPropertyAccessor
andConversionService
.- Parameters:
accessor
- must not be null.conversionService
- must not be null.
-
-
Method Details
-
setProperty
Description copied from interface:PersistentPropertyAccessor
Sets the givenPersistentProperty
to the given value. Will do type conversion if aConversionService
is configured.- Specified by:
setProperty
in 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:PersistentPropertyPathAccessor
Sets the given value for thePersistentProperty
pointed to by the givenPersistentPropertyPath
. The lookup of intermediate values must not yield null.- Specified by:
setProperty
in interfacePersistentPropertyAccessor<T>
- Specified by:
setProperty
in interfacePersistentPropertyPathAccessor<T>
- Parameters:
path
- must not be null or empty.value
- can be null.- See Also:
-
getProperty
Returns the value of the givenPersistentProperty
converted to the given type.- Parameters:
property
- must not be null.targetType
- must not be null.- Returns:
-
getTypedProperty
Returns the value of the givenPersistentProperty
potentially 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:PersistentPropertyAccessor
Returns the underlying bean. The actual instance may change betweenPersistentPropertyAccessor.setProperty(PersistentProperty, Object)
calls.- Specified by:
getBean
in interfacePersistentPropertyAccessor<T>
- Returns:
- will never be null.
-
getProperty
Description copied from interface:PersistentPropertyAccessor
Returns the value of the givenPersistentProperty
of the underlying bean instance.- Specified by:
getProperty
in interfacePersistentPropertyAccessor<T>
- Parameters:
property
- must not be null.- Returns:
- can be null.
-
getProperty
Description copied from interface:PersistentPropertyPathAccessor
Return the value pointed to by the givenPersistentPropertyPath
. If the given path is empty, the wrapped bean is returned.- Specified by:
getProperty
in interfacePersistentPropertyAccessor<T>
- Specified by:
getProperty
in 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:PersistentPropertyPathAccessor
Return 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 by handlers registered on the givenTraversalContext
context. This can be used to unwrap container types that are encountered during the traversal.- Specified by:
getProperty
in 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:PersistentPropertyPathAccessor
Sets the given value for thePersistentProperty
pointed to by the givenPersistentPropertyPath
considering the givenAccessOptions
.- Specified by:
setProperty
in interfacePersistentPropertyPathAccessor<T>
- Parameters:
path
- must not be null.value
- must not be null.options
- must not be null.
-