I am tying to generate class from xsd using JAXB and make use of default values in xsd. But when I set default value of a xs:boolean element to "true". The value is not set and I get the null-pointer exception as Boolean object value has not been initialized to true.
<xs:element name="statsEnabled" type="xs:boolean" minOccurs="0" default="true"/>
what wrong am I doing ? Can we set default values only for xs:string and not for xs:boolean ?
The xml file generated is something like this :
public class Cluster {
@XmlElement(defaultValue = "true")
protected Boolean topoEnabled;
@XmlElement(defaultValue = "true")
protected Boolean statsEnabled;
public Boolean isTopoEnabled() {
return topoEnabled;
}
public Boolean isStatsEnabled() {
return statsEnabled;
}
}
and when I try to invoke the function :
Cluster cluster = new cluster();
if(cluster.isTopoEnabled)
.....
or
if(cluster.isStatEnabled)
....
I get the null pointer error. Although in my code I have taken care of this null value.
I am just curious to know as why the default value is not working. Is there something I am doing wrong and what should I do ? or is it that default values only apply on xs:string elements and not others ?