Interface BeanUtil
-
- All Known Implementing Classes:
BeanUtilBean
public interface BeanUtil
Supreme utility for reading and writing bean properties. However, this one is the fastest available. Although it provides various methods, the whole thing can be easily extended to match most needs.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 Modifier and Type Field Description static BeanUtil
declared
static BeanUtil
declaredForced
static BeanUtil
declaredForcedSilent
static BeanUtil
declaredSilent
static BeanUtil
forced
static BeanUtil
forcedSilent
static BeanUtil
pojo
Default instance ofBeanUtilBean
.static BeanUtil
silent
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.String
extractThisReference(java.lang.String propertyName)
Returns the very first name chunk of the property.<T> T
getIndexProperty(java.lang.Object bean, java.lang.String property, int index)
Returns value of indexed property.<T> T
getProperty(java.lang.Object bean, java.lang.String name)
Returns value of bean's property.java.lang.Class<?>
getPropertyType(java.lang.Object bean, java.lang.String name)
Returns property type.<T> T
getSimpleProperty(java.lang.Object bean, java.lang.String property)
Reads simple property.boolean
hasProperty(java.lang.Object bean, java.lang.String name)
Returnstrue
if bean has a property.boolean
hasRootProperty(java.lang.Object bean, java.lang.String name)
Returnstrue
if bean has only a root property.boolean
hasSimpleProperty(java.lang.Object bean, java.lang.String property)
Returnstrue
if simple property exist.void
setIndexProperty(java.lang.Object bean, java.lang.String property, int index, java.lang.Object value)
Sets indexed property.void
setProperty(java.lang.Object bean, java.lang.String name, java.lang.Object value)
Sets Java Bean property.void
setSimpleProperty(java.lang.Object bean, java.lang.String property, java.lang.Object value)
Sets simple property.
-
-
-
Field Detail
-
pojo
static final BeanUtil pojo
Default instance ofBeanUtilBean
.
-
declared
static final BeanUtil declared
-
silent
static final BeanUtil silent
-
forced
static final BeanUtil forced
-
declaredSilent
static final BeanUtil declaredSilent
-
declaredForced
static final BeanUtil declaredForced
-
declaredForcedSilent
static final BeanUtil declaredForcedSilent
-
forcedSilent
static final BeanUtil forcedSilent
-
-
Method Detail
-
setProperty
void setProperty(java.lang.Object bean, java.lang.String name, java.lang.Object value)
Sets Java Bean property.- Parameters:
bean
- Java POJO bean or a Mapname
- property namevalue
- property value
-
setIndexProperty
void setIndexProperty(java.lang.Object bean, java.lang.String property, int index, java.lang.Object value)
Sets indexed property.
-
setSimpleProperty
void setSimpleProperty(java.lang.Object bean, java.lang.String property, java.lang.Object value)
Sets simple property.
-
getProperty
<T> T getProperty(java.lang.Object bean, java.lang.String name)
Returns value of bean's property.In silent mode, returning of
null
is ambiguous: it may means that property name is valid and property value isnull
or that property name is invalid.Using forced mode does not have any influence on the result.
-
getIndexProperty
<T> T getIndexProperty(java.lang.Object bean, java.lang.String property, int index)
Returns value of indexed property.
-
getSimpleProperty
<T> T getSimpleProperty(java.lang.Object bean, java.lang.String property)
Reads simple property.
-
hasProperty
boolean hasProperty(java.lang.Object bean, java.lang.String name)
Returnstrue
if bean has a property.
-
hasRootProperty
boolean hasRootProperty(java.lang.Object bean, java.lang.String name)
Returnstrue
if 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
boolean hasSimpleProperty(java.lang.Object bean, java.lang.String property)
Returnstrue
if simple property exist.
-
getPropertyType
java.lang.Class<?> getPropertyType(java.lang.Object bean, java.lang.String name)
Returns property type.
-
extractThisReference
java.lang.String extractThisReference(java.lang.String propertyName)
Returns the very first name chunk of the property.
-
-