Interface BeanUtil
- All Known Implementing Classes:
BeanUtilBean,BeanUtilUtil
BeanUtil supports:
- Nested properties: separated by a dot ('.')
- Indexed properties: arrays or Lists
- Simple properties: accessor or Map
Variants includes combinations of forced, declared and silent writing.
- Forced setting property tries to create destination property so it can be set correctly.
- Silent doesn't throw an exception if destination doesn't exist or if conversion fails.
- Declared includes only declared (public) properties.
This utility considers both bean property methods (set and get accessors), and bean fields. This is done because of several reasons: often there is no need for both set/get accessors, since bean logic requires just one functionality (e.g. just reading). In such case, other bean manipulation libraries still requires to have both accessors in order to set or get value. Another reason is that most common usage is to work with public accessors, and in that case private fields are ignored.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionextractThisReference(String propertyName) Returns the very first name chunk of the property.<T> TgetIndexProperty(Object bean, String property, int index) Returns value of indexed property.<T> TgetProperty(Object bean, String name) Returns value of bean's property.Class<?> getPropertyType(Object bean, String name) Returns property type.<T> TgetSimpleProperty(Object bean, String property) Reads simple property.booleanhasProperty(Object bean, String name) Returnstrueif bean has a property.booleanhasRootProperty(Object bean, String name) Returnstrueif bean has only a root property.booleanhasSimpleProperty(Object bean, String property) Returnstrueif simple property exist.voidsetIndexProperty(Object bean, String property, int index, Object value) Sets indexed property.voidsetProperty(Object bean, String name, Object value) Sets Java Bean property.voidsetSimpleProperty(Object bean, String property, Object value) Sets simple property.
-
Field Details
-
pojo
Default instance ofBeanUtilBean. -
declared
-
silent
-
forced
-
declaredSilent
-
declaredForced
-
declaredForcedSilent
-
forcedSilent
-
-
Method Details
-
setProperty
Sets Java Bean property.- Parameters:
bean- Java POJO bean or a Mapname- property namevalue- property value
-
setIndexProperty
Sets indexed property. -
setSimpleProperty
Sets simple property. -
getProperty
Returns value of bean's property.In silent mode, returning of
nullis ambiguous: it may means that property name is valid and property value isnullor that property name is invalid.Using forced mode does not have any influence on the result.
-
getIndexProperty
Returns value of indexed property. -
getSimpleProperty
Reads simple property. -
hasProperty
Returnstrueif bean has a property. -
hasRootProperty
Returnstrueif bean has only a root property. If yes, this means that property may be injected into the bean. If not, bean does not contain the property. -
hasSimpleProperty
Returnstrueif simple property exist. -
getPropertyType
Returns property type. -
extractThisReference
Returns the very first name chunk of the property.
-