org.springframework.data.mapping.model

## Class ConvertingPropertyAccessor<T>

- java.lang.Object
- - org.springframework.data.mapping.model.ConvertingPropertyAccessor<T>

All Implemented Interfaces:
  PersistentPropertyAccessor<T>, PersistentPropertyPathAccessor<T>

    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.

Author:
  Oliver Gierke, Mark Paluch

### Constructor Summary

Constructors
Constructor and Description
`ConvertingPropertyAccessor(PersistentPropertyAccessor<T> accessor, ConversionService conversionService)` Creates a new `ConvertingPropertyAccessor` for the given delegate `PersistentPropertyAccessor` and `ConversionService`.

### Method Summary

All Methods Instance Methods Concrete Methods
`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`.

### 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 Detail

#### ConvertingPropertyAccessor

    public ConvertingPropertyAccessor(PersistentPropertyAccessor<T> accessor,
                                      ConversionService conversionService)

Creates a new `ConvertingPropertyAccessor` for the given delegate `PersistentPropertyAccessor` and `ConversionService`.

Parameters:
  `accessor` - must not be null.
  `conversionService` - must not be null.

### Method Detail

#### setProperty

    public void setProperty(PersistentProperty<?> property,
                            @Nullable
                            Object value)

Description copied from interface: `PersistentPropertyAccessor`
Sets the given `PersistentProperty` to the given value. Will do type conversion if a `ConversionService` is configured.

Specified by:
  `setProperty` in interface `PersistentPropertyAccessor<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 the `PersistentProperty` pointed to by the given `PersistentPropertyPath`. The lookup of intermediate values must not yield null.

Specified by:
  `setProperty` in interface `PersistentPropertyAccessor<T>`
Specified by:
  `setProperty` in interface `PersistentPropertyPathAccessor<T>`
Parameters:
  `path` - must not be null or empty.
  `value` - can be null.
See Also:
  `AccessOptions#DEFAULT`

#### getProperty

    @Nullable
    public <S> S getProperty(PersistentProperty<?> property,
                                       Class<S> targetType)

Returns the value of the given `PersistentProperty` converted to the given type.

Parameters:
  `property` - must not be null.
  `targetType` - must not be null.
Returns:

#### getTypedProperty

    @Nullable
    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. The default implementation will not attempt any conversion and reject a type mismatch with a `MappingException`.

Parameters:
  `property` - will never be null.
  `type` - will never be null.
Returns:
  can be null.

#### getBean

    public T getBean()

Description copied from interface: `PersistentPropertyAccessor`
Returns the underlying bean. The actual instance may change between `PersistentPropertyAccessor.setProperty(PersistentProperty, Object)` calls.

Specified by:
  `getBean` in interface `PersistentPropertyAccessor<T>`
Returns:
  will never be null.

#### getProperty

    @Nullable
    public Object getProperty(PersistentProperty<?> property)

Description copied from interface: `PersistentPropertyAccessor`
Returns the value of the given `PersistentProperty` of the underlying bean instance.

Specified by:
  `getProperty` in interface `PersistentPropertyAccessor<T>`
Parameters:
  `property` - must not be null.
Returns:
  can be null.

#### getProperty

    @Nullable
    public Object getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path)

Description copied from interface: `PersistentPropertyPathAccessor`
Return the value pointed to by the given `PersistentPropertyPath`. If the given path is empty, the wrapped bean is returned.

Specified by:
  `getProperty` in interface `PersistentPropertyAccessor<T>`
Specified by:
  `getProperty` in interface `PersistentPropertyPathAccessor<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 given `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.

Specified by:
  `getProperty` in interface `PersistentPropertyPathAccessor<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 the `PersistentProperty` pointed to by the given `PersistentPropertyPath` considering the given `AccessOptions`.

Specified by:
  `setProperty` in interface `PersistentPropertyPathAccessor<T>`
Parameters:
  `path` - must not be null.
  `value` - must not be null.
  `options` - must not be null.