Reputation: 1872
Is there knowing java reflection library which can get value of fields easily. Ex . If I have Address Object inside User Object. And Address object have city attribute.
public class Address {
private String city;
}
public class User {
private String name;
private Address address;
}
Then i want to pass address.city as parameter with User Object and i want to get city of user.
Is there any library which support my requirement.
Upvotes: 3
Views: 2966
Reputation: 300
Apache commons beanutils has
PropertyUtils.getNestedProperty(user, "address.city")
.
You can also do PropertyUtils.setNestedProperty(user, "address.city", "new city")
but you need to make sure that address is not null.
Upvotes: 6