Package org.springframework.beans

# Class BeanWrapperImpl

java.lang.Object
org.springframework.beans.PropertyEditorRegistrySupport
org.springframework.beans.TypeConverterSupport
org.springframework.beans.AbstractPropertyAccessor
org.springframework.beans.AbstractNestablePropertyAccessor
org.springframework.beans.BeanWrapperImpl

All Implemented Interfaces:
  `BeanWrapper`, `ConfigurablePropertyAccessor`, `PropertyAccessor`, `PropertyEditorRegistry`, `TypeConverter`

public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements BeanWrapper
Default `BeanWrapper` implementation that should be sufficient for all typical use cases. Caches introspection results for efficiency.

Note: Auto-registers default property editors from the `org.springframework.beans.propertyeditors` package, which apply in addition to the JDK's standard PropertyEditors. Applications can call the `PropertyEditorRegistrySupport.registerCustomEditor(Class, java.beans.PropertyEditor)` method to register an editor for a particular instance (i.e. they are not shared across the application). See the base class `PropertyEditorRegistrySupport` for details.

NOTE: As of Spring 2.5, this is - for almost all purposes - an internal class. It is just public in order to allow for access from other framework packages. For standard application access purposes, use the `PropertyAccessorFactory.forBeanPropertyAccess(java.lang.Object)` factory method instead.

Since:
  15 April 2001
Author:
  Rod Johnson, Juergen Hoeller, Rob Harrop, Stephane Nicoll
See Also:
  - `PropertyEditorRegistrySupport.registerCustomEditor(java.lang.Class<?>, java.beans.PropertyEditor)`
  - `AbstractPropertyAccessor.setPropertyValues(java.util.Map<?, ?>)`
  - `AbstractNestablePropertyAccessor.setPropertyValue(java.lang.String, java.lang.Object)`
  - `AbstractNestablePropertyAccessor.getPropertyValue(java.lang.String)`
  - `AbstractNestablePropertyAccessor.getPropertyType(java.lang.String)`
  - `BeanWrapper`
  - `PropertyEditorRegistrySupport`

## Nested Class Summary

## Nested classes/interfaces inherited from class org.springframework.beans.AbstractNestablePropertyAccessor

`AbstractNestablePropertyAccessor.PropertyHandler, AbstractNestablePropertyAccessor.PropertyTokenHolder`

## Field Summary

### Fields inherited from interface org.springframework.beans.PropertyAccessor

`NESTED_PROPERTY_SEPARATOR, NESTED_PROPERTY_SEPARATOR_CHAR, PROPERTY_KEY_PREFIX, PROPERTY_KEY_PREFIX_CHAR, PROPERTY_KEY_SUFFIX, PROPERTY_KEY_SUFFIX_CHAR`

## Constructor Summary

Constructors
Constructor
Description
`BeanWrapperImpl()`
Create a new empty BeanWrapperImpl.
`BeanWrapperImpl(boolean registerDefaultEditors)`
Create a new empty BeanWrapperImpl.
`BeanWrapperImpl(Class<?> clazz)`
Create a new BeanWrapperImpl, wrapping a new instance of the specified class.
`BeanWrapperImpl(Object object)`
Create a new BeanWrapperImpl for the given object.
`BeanWrapperImpl(Object object, String nestedPath, Object rootObject)`
Create a new BeanWrapperImpl for the given object, registering a nested path that the object is in.

## Method Summary

Modifier and Type
Method
Description
`Object`
`convertForProperty(Object value, String propertyName)`
Convert the given value for the specified property to the latter's type.
`protected NotWritablePropertyException`
`createNotWritablePropertyException(String propertyName)`
Create a `NotWritablePropertyException` for the specified property.
`protected org.springframework.beans.BeanWrapperImpl.BeanPropertyHandler`
`getLocalPropertyHandler(String propertyName)`
Return a `AbstractNestablePropertyAccessor.PropertyHandler` for the specified local `propertyName`.
`PropertyDescriptor`
`getPropertyDescriptor(String propertyName)`
Obtain the property descriptor for a specific property of the wrapped object.
`PropertyDescriptor[]`
`getPropertyDescriptors()`
Obtain the PropertyDescriptors for the wrapped object (as determined by standard JavaBeans introspection).
`protected BeanWrapperImpl`
`newNestedPropertyAccessor(Object object, String nestedPath)`
Create a new nested property accessor instance.
`void`
`setBeanInstance(Object object)`
Set a bean instance to hold, without any unwrapping of `Optional`.
`protected void`
`setIntrospectionClass(Class<?> clazz)`
Set the class to introspect.
`void`
`setWrappedInstance(Object object, String nestedPath, Object rootObject)`
Switch the target object, replacing the cached introspection results only if the class of the new object is different to that of the replaced object.

### Methods inherited from class org.springframework.beans.AbstractNestablePropertyAccessor

`convertForProperty, getAutoGrowCollectionLimit, getFinalPath, getNestedPath, getPropertyAccessorForPropertyPath, getPropertyHandler, getPropertyType, getPropertyTypeDescriptor, getPropertyValue, getPropertyValue, getRootClass, getRootInstance, getWrappedClass, getWrappedInstance, isReadableProperty, isWritableProperty, setAutoGrowCollectionLimit, setPropertyValue, setPropertyValue, setPropertyValue, setWrappedInstance, toString`

### Methods inherited from class org.springframework.beans.AbstractPropertyAccessor

`isAutoGrowNestedPaths, isExtractOldValueForEditor, setAutoGrowNestedPaths, setExtractOldValueForEditor, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValues`

### Methods inherited from class org.springframework.beans.TypeConverterSupport

`convertIfNecessary, convertIfNecessary, convertIfNecessary, convertIfNecessary`

### Methods inherited from class org.springframework.beans.PropertyEditorRegistrySupport

`copyCustomEditorsTo, copyDefaultEditorsTo, findCustomEditor, getConversionService, getDefaultEditor, guessPropertyTypeFromEditors, hasCustomEditorForElement, overrideDefaultEditor, registerCustomEditor, registerCustomEditor, registerDefaultEditors, setConversionService, setDefaultEditorRegistrar, useConfigValueEditors`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.springframework.beans.BeanWrapper

`getAutoGrowCollectionLimit, getWrappedClass, getWrappedInstance, setAutoGrowCollectionLimit`

### Methods inherited from interface org.springframework.beans.ConfigurablePropertyAccessor

`getConversionService, isAutoGrowNestedPaths, isExtractOldValueForEditor, setAutoGrowNestedPaths, setConversionService, setExtractOldValueForEditor`

### Methods inherited from interface org.springframework.beans.PropertyAccessor

`getPropertyType, getPropertyTypeDescriptor, getPropertyValue, isReadableProperty, isWritableProperty, setPropertyValue, setPropertyValue, setPropertyValues, setPropertyValues, setPropertyValues, setPropertyValues`

### Methods inherited from interface org.springframework.beans.PropertyEditorRegistry

`findCustomEditor, registerCustomEditor, registerCustomEditor`

### Methods inherited from interface org.springframework.beans.TypeConverter

`convertIfNecessary, convertIfNecessary, convertIfNecessary, convertIfNecessary`

## Constructor Details

### BeanWrapperImpl

public BeanWrapperImpl()
Create a new empty BeanWrapperImpl. Wrapped instance needs to be set afterwards. Registers default editors.

See Also:
  - `setWrappedInstance(java.lang.Object, java.lang.String, java.lang.Object)`

### BeanWrapperImpl

public BeanWrapperImpl(boolean registerDefaultEditors)
Create a new empty BeanWrapperImpl. Wrapped instance needs to be set afterwards.

Parameters:
  `registerDefaultEditors` - whether to register default editors (can be suppressed if the BeanWrapper won't need any type conversion)
See Also:
  - `setWrappedInstance(java.lang.Object, java.lang.String, java.lang.Object)`

### BeanWrapperImpl

public BeanWrapperImpl(Object object)
Create a new BeanWrapperImpl for the given object.

Parameters:
  `object` - the object wrapped by this BeanWrapper

### BeanWrapperImpl

public BeanWrapperImpl(Class<?> clazz)
Create a new BeanWrapperImpl, wrapping a new instance of the specified class.

Parameters:
  `clazz` - class to instantiate and wrap

### BeanWrapperImpl

public BeanWrapperImpl(Object object, String nestedPath, Object rootObject)
Create a new BeanWrapperImpl for the given object, registering a nested path that the object is in.

Parameters:
  `object` - the object wrapped by this BeanWrapper
  `nestedPath` - the nested path of the object
  `rootObject` - the root object at the top of the path

## Method Details

### setBeanInstance

public void setBeanInstance(Object object)
Set a bean instance to hold, without any unwrapping of `Optional`.

Parameters:
  `object` - the actual target object
Since:
  4.3
See Also:
  - `AbstractNestablePropertyAccessor.setWrappedInstance(Object)`

### setWrappedInstance

public void setWrappedInstance(Object object, @Nullable String nestedPath, @Nullable Object rootObject)
Description copied from class: `AbstractNestablePropertyAccessor`
Switch the target object, replacing the cached introspection results only if the class of the new object is different to that of the replaced object.

Overrides:
  `setWrappedInstance` in class `AbstractNestablePropertyAccessor`
Parameters:
  `object` - the new target object
  `nestedPath` - the nested path of the object
  `rootObject` - the root object at the top of the path

### setIntrospectionClass

protected void setIntrospectionClass(Class<?> clazz)
Set the class to introspect. Needs to be called when the target object changes.

Parameters:
  `clazz` - the class to introspect

### convertForProperty

@Nullable public Object convertForProperty(@Nullable Object value, String propertyName) throws TypeMismatchException
Convert the given value for the specified property to the latter's type.

This method is only intended for optimizations in a BeanFactory. Use the `convertIfNecessary` methods for programmatic conversion.

Parameters:
  `value` - the value to convert
  `propertyName` - the target property (note that nested or indexed properties are not supported here)
Returns:
  the new value, possibly the result of type conversion
Throws:
  `TypeMismatchException` - if type conversion failed

### getLocalPropertyHandler

@Nullable protected org.springframework.beans.BeanWrapperImpl.BeanPropertyHandler getLocalPropertyHandler(String propertyName)
Description copied from class: `AbstractNestablePropertyAccessor`
Return a `AbstractNestablePropertyAccessor.PropertyHandler` for the specified local `propertyName`. Only used to reach a property available in the current context.

Specified by:
  `getLocalPropertyHandler` in class `AbstractNestablePropertyAccessor`
Parameters:
  `propertyName` - the name of a local property
Returns:
  the handler for that property, or `null` if it has not been found

### newNestedPropertyAccessor

protected BeanWrapperImpl newNestedPropertyAccessor(Object object, String nestedPath)
Description copied from class: `AbstractNestablePropertyAccessor`
Create a new nested property accessor instance. Can be overridden in subclasses to create a PropertyAccessor subclass.

Specified by:
  `newNestedPropertyAccessor` in class `AbstractNestablePropertyAccessor`
Parameters:
  `object` - the object wrapped by this PropertyAccessor
  `nestedPath` - the nested path of the object
Returns:
  the nested PropertyAccessor instance

### createNotWritablePropertyException

protected NotWritablePropertyException createNotWritablePropertyException(String propertyName)
Description copied from class: `AbstractNestablePropertyAccessor`
Create a `NotWritablePropertyException` for the specified property.

Specified by:
  `createNotWritablePropertyException` in class `AbstractNestablePropertyAccessor`

### getPropertyDescriptors

public PropertyDescriptor[] getPropertyDescriptors()
Description copied from interface: `BeanWrapper`
Obtain the PropertyDescriptors for the wrapped object (as determined by standard JavaBeans introspection).

Specified by:
  `getPropertyDescriptors` in interface `BeanWrapper`
Returns:
  the PropertyDescriptors for the wrapped object

### getPropertyDescriptor

public PropertyDescriptor getPropertyDescriptor(String propertyName) throws InvalidPropertyException
Description copied from interface: `BeanWrapper`
Obtain the property descriptor for a specific property of the wrapped object.

Specified by:
  `getPropertyDescriptor` in interface `BeanWrapper`
Parameters:
  `propertyName` - the property to obtain the descriptor for (may be a nested path, but not an indexed/mapped property)
Returns:
  the property descriptor for the specified property
Throws:
  `InvalidPropertyException` - if there is no such property