Java bean, BeanUtils and Boolean wrapper classes
I used bean utils to manipulate Java objects created through JAXB, and I encountered an interesting problem Sometimes, JAXB creates such a Java object:
public class Bean { protected Boolean happy; public Boolean isHappy() { return happy; } public void setHappy(Boolean happy) { this.happy = happy; } }
The following codes work correctly:
Bean bean = new Bean(); BeanUtils.setProperty(bean,"happy",true);
However, the property that seeks happiness is as follows:
Bean bean = new Bean(); BeanUtils.getProperty(bean,"happy");
Cause this exception:
Exception in thread "main" java.lang.NoSuchMethodException: Property 'happy' has no getter method in class 'class Bean'
Changing everything to the original Boolean allows both set and get calls to work However, I don't have this option because these are generated classes I think this is because the Java Bean library only considers a method that represents an attribute if the return type is an original Boolean value rather than a wrapper type Boolean Does anyone have any suggestions on how to access such properties through BeanUtils? Are there any solutions you can use?
Solution
Finally, I found that the law confirmed:
From JavaBeans specification Are you sure you haven't encountered a jaxb-131 error?