Jakarta BeanUtils PropertyUtils Nested Properties
I have mentioned the Jakarta BeanUtils project before (see Jakarta BeanUtils PropertyUtils). The PropertyUtils class of the BeanUtils project allows you to dynamically access a JavaBean property. PropertyUtils gives you access to mapped, indexed, and simple properties via get/setMappedProperty, get/setIndexedProperty, and get/setSimpleProperty.
PropertyUtils also provides a generic getProperty method which can be used to access any arbitrary combination of mapped, indexed, or simple properties. I’ve taken an example from the BeanUtils documentation. Instead of this:
String city = employee.getSubordinate(1)
.getAddress("home")
.getCity();
You can write:
String city = (String)Property.getProperty(
employee, "subordinate[1].address(home).city");