When an element has minOccurs="0"
the corresponding @XmlElement
has required=false
. Note that false
is the default value of the required
attribute so it may not actually appear in the generated annotation.
UPDATE
Based on your comment:
Let me explain my actual problem. I'm using Jackson to generate the
JSON from the JAXB classes. Issue is when the element is not
present in the xml, I see the json output with the field name as 'pip'
and value as null. I am actually expecting the field 'pip' to be
absent from my json output as I declared it to be minOccurs=0 in the
XSD. Can't figure out if it's an issue with JAXB or Jackson.
Interestingly when I annotate the field explicitly with required=false
in the jaxb class, I see my expected output with the field being
absent
This is an issue with Jackson not handling the default value of the required
property on the @XmlElement
annotation correctly.
micOccurs=0
in the XSD it would do the job. But when I did so, xjc is not adding the@XmlElement(required = false)
annotation by default to the field in the jaxb class. – Ganga Aloorischemagen
to tool to generate the schema from jaxb classes, I see that the field is added withminOccurs=0
attribute in the generated schema – Ganga Aloori