Reputation: 69
Whats the difference?! I'm generating Java Classes and I want Know if that would make a difference
public String getFiuRefNumber()
//vs
public JAXBElement<String> getFiuRefNumber()
Upvotes: 0
Views: 48
Reputation: 206776
I assume you are generating Java classes from an XSD.
JAXB will generate a JAXBElement<...>
under some circumstances. For example, when you have an element in your XSD which is optional (minOccurs="0"
) and that is also nillable, it will do this.
This is because otherwise there would be no way in Java to distinguish between the element not being present in XML at all and the element being present, but with an explicit xsi:nil="true"
attribute.
When the field is a JAXBElement
, this distinction can be made: not present in XML => Java field will be null
, present in XML but with xsi:nil="true"
=> Java field will not be null
but will be set to a JAXBElement
without a value.
If you want to avoid getting JAXBElement
fields, then you can either modify the XSD so that the element is not both optional and nillable, or you can explicitly specify with a bindings configuration file that you do not want element wrappers.
Upvotes: 1