I have an object that contains sub properties, which also have sub properties and so on.
I basically need to find the best way to retrieve the value of a particular field on the object, given it's full hierarchical path as a string.
For example, if the object has the field company (Object) which has the field client (Object) which has the field id (String), this path will be represented as company.client.id. Therefore, given a path to the field i'm trying to get the value of on an object, how would I go about doing this?
Cheers.
You can use Apache Commons BeanUtils PropertyUtilsBean.
Example of use :
PropertyUtilsBean pub = new PropertyUtilsBean();
Object property = pub.getProperty(yourObject, "company.client.id");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With