public class ConvertingPropertyAccessor<T> extends Object
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.Constructor and Description |
---|
ConvertingPropertyAccessor(PersistentPropertyAccessor<T> accessor,
ConversionService conversionService)
Creates a new
ConvertingPropertyAccessor for the given delegate PersistentPropertyAccessor and
ConversionService . |
Modifier and Type | Method and Description |
---|---|
T |
getBean()
Returns the underlying bean.
|
Object |
getProperty(PersistentProperty<?> property)
Returns the value of the given
PersistentProperty of the underlying bean instance. |
<S> S |
getProperty(PersistentProperty<?> property,
Class<S> targetType)
Returns the value of the given
PersistentProperty converted to the given type. |
Object |
getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path)
Return the value pointed to by the given
PersistentPropertyPath . |
Object |
getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path,
AccessOptions.GetOptions options)
Return the value pointed to by the given
PersistentPropertyPath . |
protected <S> S |
getTypedProperty(PersistentProperty<?> property,
Class<S> type)
Returns the value of the given
PersistentProperty potentially applying type conversion to the given target
type. |
void |
setProperty(PersistentProperty<?> property,
Object value)
Sets the given
PersistentProperty to the given value. |
void |
setProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path,
Object value)
Sets the given value for the
PersistentProperty pointed to by the given PersistentPropertyPath . |
void |
setProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path,
Object value,
AccessOptions.SetOptions options)
Sets the given value for the
PersistentProperty pointed to by the given PersistentPropertyPath
considering the given AccessOptions . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getProperty
public ConvertingPropertyAccessor(PersistentPropertyAccessor<T> accessor, ConversionService conversionService)
ConvertingPropertyAccessor
for the given delegate PersistentPropertyAccessor
and
ConversionService
.accessor
- must not be null.conversionService
- must not be null.public void setProperty(PersistentProperty<?> property, @Nullable Object value)
PersistentPropertyAccessor
PersistentProperty
to the given value. Will do type conversion if a
ConversionService
is configured.setProperty
in interface PersistentPropertyAccessor<T>
property
- must not be null.value
- can be null.public void setProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, @Nullable Object value)
PersistentPropertyPathAccessor
PersistentProperty
pointed to by the given PersistentPropertyPath
. The
lookup of intermediate values must not yield null.setProperty
in interface PersistentPropertyAccessor<T>
setProperty
in interface PersistentPropertyPathAccessor<T>
path
- must not be null or empty.value
- can be null.AccessOptions#DEFAULT
@Nullable public <S> S getProperty(PersistentProperty<?> property, Class<S> targetType)
PersistentProperty
converted to the given type.property
- must not be null.targetType
- must not be null.@Nullable protected <S> S getTypedProperty(PersistentProperty<?> property, Class<S> type)
PersistentProperty
potentially applying type conversion to the given target
type. The default implementation will not attempt any conversion and reject a type mismatch with a
MappingException
.property
- will never be null.type
- will never be null.public T getBean()
PersistentPropertyAccessor
PersistentPropertyAccessor.setProperty(PersistentProperty, Object)
calls.getBean
in interface PersistentPropertyAccessor<T>
@Nullable public Object getProperty(PersistentProperty<?> property)
PersistentPropertyAccessor
PersistentProperty
of the underlying bean instance.getProperty
in interface PersistentPropertyAccessor<T>
property
- must not be null.@Nullable public Object getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path)
PersistentPropertyPathAccessor
PersistentPropertyPath
. If the given path is empty, the wrapped
bean is returned.getProperty
in interface PersistentPropertyAccessor<T>
getProperty
in interface PersistentPropertyPathAccessor<T>
path
- must not be null.@Nullable public Object getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, AccessOptions.GetOptions options)
PersistentPropertyPathAccessor
PersistentPropertyPath
. 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 given TraversalContext
context. This can be used to unwrap container types that are encountered
during the traversal.getProperty
in interface PersistentPropertyPathAccessor<T>
path
- must not be null.options
- must not be null.public void setProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, @Nullable Object value, AccessOptions.SetOptions options)
PersistentPropertyPathAccessor
PersistentProperty
pointed to by the given PersistentPropertyPath
considering the given AccessOptions
.setProperty
in interface PersistentPropertyPathAccessor<T>
path
- must not be null.value
- must not be null.options
- must not be null.Copyright © 2011–2020 Pivotal Software, Inc.. All rights reserved.