org.springframework.data.mapping.model

## Class InstantiationAwarePropertyAccessor<T>

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

All Implemented Interfaces:
  PersistentPropertyAccessor<T>

    public class InstantiationAwarePropertyAccessor<T>
    extends Object
    implements PersistentPropertyAccessor<T>

A `PersistentPropertyAccessor` that will use an entity's `PersistenceConstructor` to create a new instance of it to apply a new value for a given `PersistentProperty`. Will only be used if the `PersistentProperty` is to be applied on a completely immutable entity type exposing a persistence constructor.

Since:
  2.3
Author:
  Oliver Drotbohm, Mark Paluch

### Constructor Summary

Constructors
Constructor and Description
`InstantiationAwarePropertyAccessor(PersistentPropertyAccessor<T> delegate, EntityInstantiators instantiators)` Deprecated. since 2.4. Using this constructor allows only setting a single property as `PersistentPropertyAccessor` holds a reference to the initial bean state.
`InstantiationAwarePropertyAccessor(T bean, Function<T,PersistentPropertyAccessor<T>> accessorFunction, EntityInstantiators instantiators)` Creates an `InstantiationAwarePropertyAccessor` using the given delegate `accessorFunction` and `EntityInstantiators`.

### 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.
`void` `setProperty(PersistentProperty<?> property, Object value)` Sets the given `PersistentProperty` to the given value.

### 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, getProperty, setProperty`

### Constructor Detail

#### InstantiationAwarePropertyAccessor

    @Deprecated
    public InstantiationAwarePropertyAccessor(PersistentPropertyAccessor<T> delegate,
                                                          EntityInstantiators instantiators)

Deprecated. since 2.4. Using this constructor allows only setting a single property as `PersistentPropertyAccessor` holds a reference to the initial bean state.
Creates an `InstantiationAwarePropertyAccessor` using the given delegate `PersistentPropertyAccessor` and `EntityInstantiators`.

Parameters:
  `delegate` - must not be null.
  `instantiators` - must not be null.

#### InstantiationAwarePropertyAccessor

    public InstantiationAwarePropertyAccessor(T bean,
                                              Function<T,PersistentPropertyAccessor<T>> accessorFunction,
                                              EntityInstantiators instantiators)

Creates an `InstantiationAwarePropertyAccessor` using the given delegate `accessorFunction` and `EntityInstantiators`. `accessorFunction` is used to obtain a new `PersistentPropertyAccessor` for each property to set.

Parameters:
  `bean` - must not be null.
  `accessorFunction` - must not be null.
  `instantiators` - must not be null.
Since:
  2.4

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

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

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