I'm using BeanUtils to manipulate Java objects created via JAXB, and I've run into an interesting issue. Sometimes, JAXB will create a Java object like this:
public class Bean {
protected Boolean happy;
public Boolean isHappy() {
return happy;
}
public void setHappy(Boolean happy) {
this.happy = happy;
}
}
The following code works just fine:
Bean bean = new Bean();
BeanUtils.setProperty(bean, "happy", true);
However, attempting to get the happy
property like so:
Bean bean = new Bean();
BeanUtils.getProperty(bean, "happy");
Results in this exception:
Exception in thread "main" java.lang.NoSuchMethodException: Property 'happy' has no getter method in class 'class Bean'
Changing everything to a primitive boolean
allows both the set and get call to work. I don't have this option, however, since these are generated classes. I assume this happens because the Java Bean libraries only consider an is<name>
method to represent a property if the return type is a primitive boolean
, and not the wrapper type Boolean
. Does anyone have a suggestion as to how to access properties like these through BeanUtils? Is there some kind of workaround I can use?
BeanUtils
class come from? I checked withorg.apache.commons.beanutils.BeanUtils
(1.8.3) and it works fine. Please note that typicallyis
prefix is used forboolean
, while forBoolean
:get
. – AutoionizationgetProperty()
with anis
method that returns theBoolean
wrapper class? – NettienettinggetProperty()
does not work withBoolean is
. In fact, IntelliJ generates getters withget
forBoolean
andis
forboolean
- I guess Eclipse does the same. – Autoionization