Apache Commons BeanUtils is a java library useful for accessing bean properties and methods.
It provides introspection capabilities to view and manipulate the properties and operations provided
by the given class.
This requires the libraries commons-beanutils-1.8.3.jar,
commons-beanutils-bean-collections-1.8.3.jar, commons-beanutils-core-1.8.3.jar,
commons-collections-3.2.1.jar, commons-logging.jar to be in classpath.
The following example shows using PropertyUtils.getPropertyDescriptors() API.
It returns all property descriptors for the specified bean.
for (PropertyDescriptor descriptor : descriptors) {
//Get read method from descriptor
System.out.println(descriptor.getReadMethod());
}
}
}
It gives the following output,
public int com.bethecoder.tutorials.commons_beanutils.common.Student.getAge()
public final native java.lang.Class java.lang.Object.getClass()
public java.lang.String com.bethecoder.tutorials
.commons_beanutils.common.Student.getHobby()
public java.lang.String com.bethecoder.tutorials
.commons_beanutils.common.Student.getName()