Apache Commons BeanUtils

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
Apache Commons BeanUtils
DeveloperApache Software Foundation
Stable release
1.9.4
Repositoryhttps://github.com/apache/commons-beanutils
Written inJava
Engine
    Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
    Operating systemCross-platform
    LicenseApache License 2.0
    Websitecommons.apache.org/proper/commons-beanutils/index.html

    Apache Commons BeanUtils is a Java-based utility to provide component based architecture.[1][2][3]

    Modules

    [edit | edit source]

    The library is distributed in three jar files:

    • commons-beanutils.jar - contains everything
    • commons-beanutils-core.jar - excludes Bean Collections classes
    • commons-beanutils-bean-collections.jar - only Bean Collections classes.[1]

    Example

    [edit | edit source]

    Sample code may look like as follows:

    /**
    * Example displaying the new default behaviour such that
    * it is not possible to access class level properties utilizing the
    * BeanUtilsBean, which in turn utilizes the PropertyUtilsBean.
    */
    public void testSuppressClassPropertyByDefault() throws Exception {
        final BeanUtilsBean bub = new BeanUtilsBean();
        final AlphaBean bean = new AlphaBean();
        try {
            bub.getProperty(bean, "class");
            fail("Could access class property!");
        } catch (final NoSuchMethodException ex) {
            // Ok
        }
    }
    
    /**
    * Example showing how by which one would use to revert to the
    * behaviour prior to the 1.9.4 release where class level properties were accessible by
    * the BeanUtilsBean and the PropertyUtilsBean.
    */
    public void testAllowAccessToClassProperty() throws Exception {
        final BeanUtilsBean bub = new BeanUtilsBean();
        bub.getPropertyUtils().removeBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);
        final AlphaBean bean = new AlphaBean();
        String result = bub.getProperty(bean, "class");
        assertEquals("Class property should have been accessed", "class org.apache.commons.beanutils2.AlphaBean", result);
    }
    

    [1]

    See also

    [edit | edit source]

    Lua error in mw.title.lua at line 392: bad argument #2 to 'title.new' (unrecognized namespace name 'Portal').

    References

    [edit | edit source]
    1. ^ a b c Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    2. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    3. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    [edit | edit source]