Below is my bean structure. Employee.java is the parent bean. I would like to iterate through all the properties till the Zip.java and manipulate the values.
I tried to iterate this using reflection, but getDeclaredFields() will give the fields of the top level object only. How to iterate over deeper objects.
Could someone let me know how to do this in java.
Employee.java
private String id;
private String name;
private int age;
private Address addr;
private Contact cont;
Address.java
private String addr1;
private String addr2;
private String city;
private Zip zip;
Contact.java
private String phone;
private String email;
Zip.java
private String zipCd;
private String zipExt;
I did this, but I know and I strongly feel that this is considered bad programming. I did it because someone forced me to, though! (The neatest solution, I think, would've been to write more code... this was the quickest).
Where fieldName is (for zipCd): addr.zip.zipCd
It will retrieve the String value of zipCd from an Employee object.