Apache Commons logo Commons BeanUtils2

Commons BeanUtils2

Most Java developers are used to creating Java classes that conform to the JavaBeans naming patterns for property getters and setters. It is natural to then access these methods directly, using calls to the corresponding getXxx and setXxx methods. However, there are some occasions where dynamic access to Java object properties (without compiled-in knowledge of the property getter and setter methods to be called) is needed. Example use cases include:

  • Building scripting languages that interact with the Java object model (such as the Bean Scripting Framework).
  • Building template language processors for web presentation and similar uses (such as JSP or Velocity).
  • Building custom tag libraries for JSP and XSP environments (such as Jakarta Taglibs, Struts, Cocoon).
  • Consuming XML-based configuration resources (such as Ant build scripts, web application deployment descriptors, Tomcat's server.xml file).

The Java language provides Reflection and Introspection APIs (see the java.lang.reflect and java.beans packages in the JDK Javadocs). However, these APIs can be quite complex to understand and utilize. The BeanUtils2 component provides easy-to-use wrappers around these capabilities.

BeanUtils And BeanUtils2

BeanUtils2 is a complete rewrite of the Commons BeanUtils library. It is designed as a fluent API, allowing users to chain method calls one after another:

import static org.apache.commons.beanutils2.BeanUtils.on;
...
on( myBean ).set( "stringProperty" ).with( "Hello from BeanUtils2!" );

In addition to that, BeanUtils2 provides unchecked exception wrappers for the checked exceptions that are used by the Java Reflection and Introspection APIs. This releases users from the burden to catch those exceptions, that in most cases result from programmatic errors rather than runtime failures that could be reasonable handled and recovered from.

To allow backwards compatibility, BeanUtils2 lives in its own package so that it can be used side by side with BeanUtils.

Documentation

The User Guide is part of the package JavaDocs.

The Release Notes document the new features and bug fixes that have been included in this release.

The JavaDoc API documents are available online. In particular, you should note the property reference syntax options described in the PropertyUtils class description.

Status

  • This code is in the commons sandbox
  • The code is unreleased
  • Methods and classes can and will appear and disappear without warning
  • If you like the code and want to push it towards a release, join the mailing list!

Releases

None. This is a sandbox component.

Support

The commons mailing lists act as the main support forum. The user list is suitable for most library usage queries. The dev list is intended for the development discussion. Please remember that the lists are shared between all commons components, so prefix your email by [beanutils2].

Issues may be reported via ASF JIRA.