I found a use case!
(See https://stackoverflow.com/a/18984458/2886891 for detailed explanation of the bacground.)
When there is a mandatory element in the XSD schema, such as
<xsd:element name="City" type="xsd:string" minOccurs="1">
<xsd:element name="State" type="xsd:string" minOccurs="0">
and for some reason I omit to set the value in the class (missing request.setCity("London")
), the JAXB Marshaller does not generate the XML element at all.
Unfortunately, the server, instead of complaining about the missing element, returns a completely misleading message:
org.apache.axis2.databinding.ADBException: Unexpected subelement State
Notice that it complains about the presence of the next element, and not about the absence of the mandatory element.
However, if I change the XSD to
<xsd:element name="City" type="xsd:string" minOccurs="1" nillable="true">
<xsd:element name="State" type="xsd:string" minOccurs="0">
the marshaller generates
<CardCity xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
which is still invalid, but I get a meaningful error message:
org.apache.axis2.databinding.ADBException: The element: City cannot be null
Such a message is much more user-friendly and tells me immediately what I did wrong.