Package jodd.bean

Interface BeanUtil

All Known Implementing Classes:
BeanUtilBean, BeanUtilUtil

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 Details

    • pojo

      static final BeanUtil pojo
      Default instance of BeanUtilBean.
    • 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 Details

    • setProperty

      void setProperty(Object bean, String name, Object value)
      Sets Java Bean property.
      Parameters:
      bean - Java POJO bean or a Map
      name - property name
      value - property value
    • setIndexProperty

      void setIndexProperty(Object bean, String property, int index, Object value)
      Sets indexed property.
    • setSimpleProperty

      void setSimpleProperty(Object bean, String property, Object value)
      Sets simple property.
    • getProperty

      <T> T getProperty(Object bean, 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 is null or that property name is invalid.

      Using forced mode does not have any influence on the result.

    • getIndexProperty

      <T> T getIndexProperty(Object bean, String property, int index)
      Returns value of indexed property.
    • getSimpleProperty

      <T> T getSimpleProperty(Object bean, String property)
      Reads simple property.
    • hasProperty

      boolean hasProperty(Object bean, String name)
      Returns true if bean has a property.
    • hasRootProperty

      boolean hasRootProperty(Object bean, String name)
      Returns true 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(Object bean, String property)
      Returns true if simple property exist.
    • getPropertyType

      Class<?> getPropertyType(Object bean, String name)
      Returns property type.
    • extractThisReference

      String extractThisReference(String propertyName)
      Returns the very first name chunk of the property.