3

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.

1
  • It takes five minutes to write such a thing yourself… Commented May 3, 2016 at 12:58

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.