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");

Related posts:

  1. Jakarta BeanUtils PropertyUtils
  2. Jakarta Commons Lang Builders
  3. Jakarta Commons IO
  4. Java Nested Inner Class This
  5. JavaBeans

This entry was posted in Java, TechKnow. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*