Reputation: 3647
I'm currently taking an example from here to map my ResultSet
to custom Object
. I've tested BeanUtils.setProperty()
and it seems like the object would need setters to work. Is there any way to map values like what Gson
does? I don't want to have public setters.
Upvotes: 1
Views: 2330
Reputation: 7624
No it can't.
As the name implies the BeanUtils deal with Java Beans
They are serializable, have a zero-argument constructor, and allow access to properties using getter and setter methods.
(Emphasis mine.)
Though the Javadoc of the BeanUtils methods is quite vague clues can also be found in the source code of BeanUtilsBean.setProperty()
and PropertyUtilsBean.setSimpleProperty()
.
See the documentation too:
The Java language provides classes like java.beans.Introspector, which can examine a Java class at runtime and identify for you the names of the property getter and setter methods, [...]. The APIs in the BeanUtils package are intended to simplify getting and setting bean properties dynamically, [...].
(Emphasis mine.)
Upvotes: 1