Reputation: 85
Given the following:
public class Person {
private Car car;
// .. bean stuff
}
.
public class Car {
private CarStuff carStuff;
// .. bean stuff
}
I can use BeanUtils to set the "car" property of Person:
BeanUtils.setProperty(person, "car", theirCar);
Ok that was super easy. Now how do I get "car" out by its name?
BeanUtils.getProperty(person, "car")
Will return a String, but Car is not a String
I have tried:
Map<String, ? extends Object> props = new HashMap<>();
BeanUtils.populate(person, props);
but there is no "car" entry, and investigating the documentation, the output (while promisingly of type Object) would still be either String or String[]
My classes all have proper bean getter and setter methods. How can I obtain the value?
Upvotes: 2
Views: 4629
Reputation: 452
You can try using PropertyUtils.getProperty(Object, String)
instead
Upvotes: 5