Package jodd.bean

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.

    • 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 Map
        name - property name
        value - 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 is null 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)
        Returns true if bean has a property.
      • hasRootProperty

        boolean hasRootProperty​(java.lang.Object bean,
                                java.lang.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​(java.lang.Object bean,
                                  java.lang.String property)
        Returns true 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.