A set of reflection utilities and miscellaneous utilities related to working with classes and their fields with no dependencies which is compatible with java 1.5 and generics.

Features:

These are built to be compatible with Apache Commons BeanUtils and the nesting structure works the same, refer to the apache BeanUtils project docs for details. Support for Apache DynaClass / DynaBean is included. Current users of beanutils should be able to drop in these utilities and gain the functionality with minimal code changes.

Handles field operations for properties (getters and setters), partial properties (only getter or only setter), and fields. This is configurable to use the fields only, properties only, or the hybrid approach (default). This improves upon the BeanUtils limitation of handling only properties or the Google utilities limitation of handling only fields.

Getting and setting fields supports simple, nested, indexed, and mapped values

Includes support for dealing with annotations and working with fields which have annotations on them. Methods for finding fields with an annotation and finding all annotations in a class or on a fields are included.

Includes support for deep cloning, deep copying, and populating objects using auto-conversion. Also includes support for fuzzy copies where object data can be copied from one object to another without the objects being the same type.

Also includes an extendable conversion system for converting between java types. This system also handles conversions between arrays, maps, collections, enums, and scalars and improves upon the apache system by handling more types and handling object holders. Support for construction of any class and a set of utilities for determining what types of objects you are working with are also included. A method for executing a specific constructor can be used if more control if needed.

Includes transcoders (encoder/decoder) for conversion of class data to and from JSON and XML. The transcoders are clean and simple and work with any type of object. They will default to converting the incoming data into maps of simple java objects but these can be converted to the correct objects using the reflection utilities if desired.

The utilities cache reflection data for high performance operation but uses weak/soft caching to avoid holding open ClassLoaders and causing the caches to exist in memory permanently. The ability to override the caching mechanism with your own is supported.

The utilities are modular and are meant to be extendable and overridable. All methods are protected or public so that the various utility classes can be easily overridden if needed.


Sample code:

Examples operate on the class at the bottom (TestEntity). There are more samples in the guide.

TestEntity.class (comes directly from the test cases)

public class TestEntity {
   private Long id = new Long(3);
   private String entityId = "33";
   \@TestAnnote
   private String extra = null;
   private Boolean bool = null;
   private String[] sArray = {"1","2"};

   public String getPrefix() {
      return "crud";
   }
   public String createEntity(Object entity) {
      return "1";
   }
   \@TestAnnote
   public String getEntityId() {
      return entityId;
   }
   public void setEntityId(String entityId) {
      this.entityId = entityId;
   }
   public Long getId() {
      return id;
   }
   public void setId(Long id) {
      this.id = id;
   }
   \@TestAnnoteField1
   public String getExtra() {
      return extra;
   }
   \@TestAnnoteField2("TEST")
   public void setExtra(String extra) {
      this.extra = extra;
   }
   public String[] getSArray() {
      return sArray;
   }
   public void setSArray(String[] array) {
      sArray = array;
   }
   public Boolean getBool() {
      return bool;
   }
   public void setBool(Boolean bool) {
      this.bool = bool;
   }
}
You are encouraged to look at the test cases (available in the source code) which illustrate uses of the utilities far better than the documentation.