This question has been asked in various guises - but I feel there is still room to catalogue this further.
I have an xsd with two element definitions
<xs:complexType name="elementA">
<xs:sequence>
<xs:element name="date" type="xs:string" minOccurs="0"/>
<xs:element name="lastXdigits" type="xs:string" nillable="true" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
This generates:
protected String date;
@XmlElementRef(name = "lastXdigits", namespace = "http://xxxxxxx", type = JAXBElement.class)
protected JAXBElement<String> lastXDigits;
Changing the xsd to:
<xs:element name="lastXdigits" type="xs:string" nillable="true" minOccurs="1"/>
results in:
protected String date;
@XmlElement(name = "lastXdigits", required = true, nillable = true)
protected String lastXDigits;
and using:
<xs:element name="lastXdigits" type="xs:string" minOccurs="0"/>
results in:
protected String date;
@XmlElement(name = "lastXdigits")
protected String lastXDigits;
This seems extremely odd to me. Why is lastXDigits generated as a JAXBElement type in the first case and why does a String type not suffice in all cases? Also, why should jaxb treat these two elements differently when their definition apart from name are identical?
I'm using a jaxb-xjc ant task from jaxb 2.0.5.
Does this look suspicious or is there good justification for these differences?
If nillable="true"
together with minOccurs="0"
it is impossible to represent the values with just a String
. What would null
mean? Does it mean that it was null, or that it occurred 0 times? But I guess that is somewhat moot when it comes to just a String.
Compare with empty list. A null list is certainly different to an empty one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With