Class PropertyUtils
Utility methods for using Java Reflection APIs to facilitate generic property getter and setter operations on Java objects.
 The implementations for these methods are provided by PropertyUtilsBean. For more details see PropertyUtilsBean.
 
- See Also:
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidaddBeanIntrospector(BeanIntrospector introspector) Adds aBeanIntrospector.static voidClear any cached property descriptors information for all classes loaded by any class loaders.static voidcopyProperties(Object dest, Object orig) Copy property values from the "origin" bean to the "destination" bean for all cases where the property names are the same (even though the actual getter and setter methods might have been customized viaBeanInfoclasses).Return the entire set of properties for which the specified bean provides a read method.static ObjectgetIndexedProperty(Object bean, String name) Return the value of the specified indexed property of the specified bean, with no type conversions.static ObjectgetIndexedProperty(Object bean, String name, int index) Return the value of the specified indexed property of the specified bean, with no type conversions.static ObjectgetMappedProperty(Object bean, String name) Return the value of the specified mapped property of the specified bean, with no type conversions.static ObjectgetMappedProperty(Object bean, String name, String key) Return the value of the specified mapped property of the specified bean, with no type conversions.static ObjectgetNestedProperty(Object bean, String name) Return the value of the (possibly nested) property of the specified name, for the specified bean, with no type conversions.static ObjectgetProperty(Object bean, String name) Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.static PropertyDescriptorgetPropertyDescriptor(Object bean, String name) Retrieve the property descriptor for the specified property of the specified bean, or returnnullif there is no such descriptor.static PropertyDescriptor[]getPropertyDescriptors(Class<?> beanClass) Retrieve the property descriptors for the specified class, introspecting and caching them the first time a particular bean class is encountered.static PropertyDescriptor[]getPropertyDescriptors(Object bean) Retrieve the property descriptors for the specified bean, introspecting and caching them the first time a particular bean class is encountered.static Class<?> getPropertyEditorClass(Object bean, String name) Return the Java Class representing the property editor class that has been registered for this property (if any).static Class<?> getPropertyType(Object bean, String name) Return the Java Class representing the property type of the specified property, ornullif there is no such property for the specified bean.static MethodgetReadMethod(PropertyDescriptor descriptor) Return an accessible property getter method for this property, if there is one; otherwise returnnull.static ObjectgetSimpleProperty(Object bean, String name) Return the value of the specified simple property of the specified bean, with no type conversions.static MethodgetWriteMethod(PropertyDescriptor descriptor) Return an accessible property setter method for this property, if there is one; otherwise returnnull.static booleanisReadable(Object bean, String name) Returntrueif the specified property name identifies a readable property on the specified bean; otherwise, returnfalse.static booleanisWriteable(Object bean, String name) Returntrueif the specified property name identifies a writable property on the specified bean; otherwise, returnfalse.static booleanremoveBeanIntrospector(BeanIntrospector introspector) Removes the specifiedBeanIntrospector.static voidResets the registeredBeanIntrospectorobjects to the initial default state.static voidsetIndexedProperty(Object bean, String name, int index, Object value) Sets the value of the specified indexed property of the specified bean, with no type conversions.static voidsetIndexedProperty(Object bean, String name, Object value) Sets the value of the specified indexed property of the specified bean, with no type conversions.static voidsetMappedProperty(Object bean, String name, Object value) Sets the value of the specified mapped property of the specified bean, with no type conversions.static voidsetMappedProperty(Object bean, String name, String key, Object value) Sets the value of the specified mapped property of the specified bean, with no type conversions.static voidsetNestedProperty(Object bean, String name, Object value) Sets the value of the (possibly nested) property of the specified name, for the specified bean, with no type conversions.static voidsetProperty(Object bean, String name, Object value) Set the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.static voidsetSimpleProperty(Object bean, String name, Object value) Set the value of the specified simple property of the specified bean, with no type conversions.
- 
Method Details- 
addBeanIntrospectorAdds aBeanIntrospector. This object is invoked when the property descriptors of a class need to be obtained.- Parameters:
- introspector- the- BeanIntrospectorto be added (must not be null
- Throws:
- IllegalArgumentException- if the argument is null
- Since:
- 1.9
 
- 
clearDescriptorsClear any cached property descriptors information for all classes loaded by any class loaders. This is useful in cases where class loaders are thrown away to implement class reloading.For more details see PropertyUtilsBean.- See Also:
 
- 
copyPropertiespublic static void copyProperties(Object dest, Object orig) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Copy property values from the "origin" bean to the "destination" bean for all cases where the property names are the same (even though the actual getter and setter methods might have been customized via BeanInfoclasses).For more details see PropertyUtilsBean.- Parameters:
- dest- Destination bean whose properties are modified
- orig- Origin bean whose properties are retrieved
- Throws:
- IllegalAccessException- if the caller does not have access to the property accessor method
- IllegalArgumentException- if the- destor- origargument is null
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
describepublic static Map<String,Object> describe(Object bean) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Return the entire set of properties for which the specified bean provides a read method. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean whose properties are to be extracted
- Returns:
- The set of properties for the bean
- Throws:
- IllegalAccessException- if the caller does not have access to the property accessor method
- IllegalArgumentException- if- beanis null
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
getIndexedPropertypublic static Object getIndexedProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Return the value of the specified indexed property of the specified bean, with no type conversions. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean whose property is to be extracted
- name-- propertyname[index]of the property value to be extracted
- Returns:
- the indexed property value
- Throws:
- IndexOutOfBoundsException- if the specified index is outside the valid range for the underlying property
- IllegalAccessException- if the caller does not have access to the property accessor method
- IllegalArgumentException- if- beanor- nameis null
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
getIndexedPropertypublic static Object getIndexedProperty(Object bean, String name, int index) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Return the value of the specified indexed property of the specified bean, with no type conversions. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean whose property is to be extracted
- name- Simple property name of the property value to be extracted
- index- Index of the property value to be extracted
- Returns:
- the indexed property value
- Throws:
- IndexOutOfBoundsException- if the specified index is outside the valid range for the underlying property
- IllegalAccessException- if the caller does not have access to the property accessor method
- IllegalArgumentException- if- beanor- nameis null
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
getMappedPropertypublic static Object getMappedProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Return the value of the specified mapped property of the specified bean, with no type conversions. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean whose property is to be extracted
- name-- propertyname(key)of the property value to be extracted
- Returns:
- the mapped property value
- Throws:
- IllegalAccessException- if the caller does not have access to the property accessor method
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
getMappedPropertypublic static Object getMappedProperty(Object bean, String name, String key) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Return the value of the specified mapped property of the specified bean, with no type conversions. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean whose property is to be extracted
- name- Mapped property name of the property value to be extracted
- key- Key of the property value to be extracted
- Returns:
- the mapped property value
- Throws:
- IllegalAccessException- if the caller does not have access to the property accessor method
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
getNestedPropertypublic static Object getNestedProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Return the value of the (possibly nested) property of the specified name, for the specified bean, with no type conversions. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean whose property is to be extracted
- name- Possibly nested name of the property to be extracted
- Returns:
- the nested property value
- Throws:
- IllegalAccessException- if the caller does not have access to the property accessor method
- IllegalArgumentException- if- beanor- nameis null
- NestedNullException- if a nested reference to a property returns null
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
getPropertypublic static Object getProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean whose property is to be extracted
- name- Possibly indexed and/or nested name of the property to be extracted
- Returns:
- the property value
- Throws:
- IllegalAccessException- if the caller does not have access to the property accessor method
- IllegalArgumentException- if- beanor- nameis null
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
getPropertyDescriptorpublic static PropertyDescriptor getPropertyDescriptor(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Retrieve the property descriptor for the specified property of the specified bean, or return nullif there is no such descriptor.For more details see PropertyUtilsBean.- Parameters:
- bean- Bean for which a property descriptor is requested
- name- Possibly indexed and/or nested name of the property for which a property descriptor is requested
- Returns:
- the property descriptor
- Throws:
- IllegalAccessException- if the caller does not have access to the property accessor method
- IllegalArgumentException- if- beanor- nameis null
- IllegalArgumentException- if a nested reference to a property returns null
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
getPropertyDescriptorsRetrieve the property descriptors for the specified class, introspecting and caching them the first time a particular bean class is encountered. For more details see PropertyUtilsBean.- Parameters:
- beanClass- Bean class for which property descriptors are requested
- Returns:
- the property descriptors
- Throws:
- IllegalArgumentException- if- beanClassis null
- See Also:
 
- 
getPropertyDescriptorsRetrieve the property descriptors for the specified bean, introspecting and caching them the first time a particular bean class is encountered. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean for which property descriptors are requested
- Returns:
- the property descriptors
- Throws:
- IllegalArgumentException- if- beanis null
- See Also:
 
- 
getPropertyEditorClasspublic static Class<?> getPropertyEditorClass(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Return the Java Class representing the property editor class that has been registered for this property (if any). For more details see PropertyUtilsBean.- Parameters:
- bean- Bean for which a property descriptor is requested
- name- Possibly indexed and/or nested name of the property for which a property descriptor is requested
- Returns:
- the property editor class
- Throws:
- IllegalAccessException- if the caller does not have access to the property accessor method
- IllegalArgumentException- if- beanor- nameis null
- IllegalArgumentException- if a nested reference to a property returns null
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
getPropertyTypepublic static Class<?> getPropertyType(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Return the Java Class representing the property type of the specified property, or nullif there is no such property for the specified bean.For more details see PropertyUtilsBean.- Parameters:
- bean- Bean for which a property descriptor is requested
- name- Possibly indexed and/or nested name of the property for which a property descriptor is requested
- Returns:
- The property type
- Throws:
- IllegalAccessException- if the caller does not have access to the property accessor method
- IllegalArgumentException- if- beanor- nameis null
- IllegalArgumentException- if a nested reference to a property returns null
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
getReadMethodReturn an accessible property getter method for this property, if there is one; otherwise return null.For more details see PropertyUtilsBean.- Parameters:
- descriptor- Property descriptor to return a getter for
- Returns:
- The read method
- See Also:
 
- 
getSimplePropertypublic static Object getSimpleProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Return the value of the specified simple property of the specified bean, with no type conversions. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean whose property is to be extracted
- name- Name of the property to be extracted
- Returns:
- The property value
- Throws:
- IllegalAccessException- if the caller does not have access to the property accessor method
- IllegalArgumentException- if- beanor- nameis null
- IllegalArgumentException- if the property name is nested or indexed
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
getWriteMethodReturn an accessible property setter method for this property, if there is one; otherwise return null.For more details see PropertyUtilsBean.- Parameters:
- descriptor- Property descriptor to return a setter for
- Returns:
- The write method
- See Also:
 
- 
isReadableReturn trueif the specified property name identifies a readable property on the specified bean; otherwise, returnfalse.For more details see PropertyUtilsBean.- Parameters:
- bean- Bean to be examined (may be a- DynaBean
- name- Property name to be evaluated
- Returns:
- trueif the property is readable, otherwise- false
- Throws:
- IllegalArgumentException- if- beanor- name</code> is <code>null
- Since:
- 1.6
- See Also:
 
- 
isWriteableReturn trueif the specified property name identifies a writable property on the specified bean; otherwise, returnfalse.For more details see PropertyUtilsBean.- Parameters:
- bean- Bean to be examined (may be a- DynaBean
- name- Property name to be evaluated
- Returns:
- trueif the property is writable, otherwise- false
- Throws:
- IllegalArgumentException- if- beanor- name</code> is <code>null
- Since:
- 1.6
- See Also:
 
- 
removeBeanIntrospectorRemoves the specifiedBeanIntrospector.- Parameters:
- introspector- the- BeanIntrospectorto be removed
- Returns:
- true if the BeanIntrospectorexisted and could be removed, false otherwise
- Since:
- 1.9
 
- 
resetBeanIntrospectorsResets the registeredBeanIntrospectorobjects to the initial default state.- Since:
- 1.9
 
- 
setIndexedPropertypublic static void setIndexedProperty(Object bean, String name, int index, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Sets the value of the specified indexed property of the specified bean, with no type conversions. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean whose property is to be set
- name- Simple property name of the property value to be set
- index- Index of the property value to be set
- value- Value to which the indexed property element is to be set
- Throws:
- IndexOutOfBoundsException- if the specified index is outside the valid range for the underlying property
- IllegalAccessException- if the caller does not have access to the property accessor method
- IllegalArgumentException- if- beanor- nameis null
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
setIndexedPropertypublic static void setIndexedProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Sets the value of the specified indexed property of the specified bean, with no type conversions. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean whose property is to be modified
- name-- propertyname[index]of the property value to be modified
- value- Value to which the specified property element should be set
- Throws:
- IndexOutOfBoundsException- if the specified index is outside the valid range for the underlying property
- IllegalAccessException- if the caller does not have access to the property accessor method
- IllegalArgumentException- if- beanor- nameis null
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
setMappedPropertypublic static void setMappedProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Sets the value of the specified mapped property of the specified bean, with no type conversions. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean whose property is to be set
- name-- propertyname(key)of the property value to be set
- value- The property value to be set
- Throws:
- IllegalAccessException- if the caller does not have access to the property accessor method
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
setMappedPropertypublic static void setMappedProperty(Object bean, String name, String key, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Sets the value of the specified mapped property of the specified bean, with no type conversions. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean whose property is to be set
- name- Mapped property name of the property value to be set
- key- Key of the property value to be set
- value- The property value to be set
- Throws:
- IllegalAccessException- if the caller does not have access to the property accessor method
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
setNestedPropertypublic static void setNestedProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Sets the value of the (possibly nested) property of the specified name, for the specified bean, with no type conversions. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean whose property is to be modified
- name- Possibly nested name of the property to be modified
- value- Value to which the property is to be set
- Throws:
- IllegalAccessException- if the caller does not have access to the property accessor method
- IllegalArgumentException- if- beanor- nameis null
- IllegalArgumentException- if a nested reference to a property returns null
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
setPropertypublic static void setProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Set the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean whose property is to be modified
- name- Possibly indexed and/or nested name of the property to be modified
- value- Value to which this property is to be set
- Throws:
- IllegalAccessException- if the caller does not have access to the property accessor method
- IllegalArgumentException- if- beanor- nameis null
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
- 
setSimplePropertypublic static void setSimpleProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Set the value of the specified simple property of the specified bean, with no type conversions. For more details see PropertyUtilsBean.- Parameters:
- bean- Bean whose property is to be modified
- name- Name of the property to be modified
- value- Value to which the property should be set
- Throws:
- IllegalAccessException- if the caller does not have access to the property accessor method
- IllegalArgumentException- if- beanor- nameis null
- IllegalArgumentException- if the property name is nested or indexed
- InvocationTargetException- if the property accessor method throws an exception
- NoSuchMethodException- if an accessor method for this property cannot be found
- See Also:
 
 
-