JAXB code generation: how to remove a zero occurrence field?
- by reef
Hi all,
I use JAXB 2.1 to generate Java classes from several XSD files, and I have a problem related to complex type restriction.
On of the restrictions modifies the occurence configuration from minOccurs="0" maxOccurs="unbounded" to minOccurs="0" maxOccurs="0". Thus this field is not needed anymore in the restricted type. But actually JAXB generates the restricted class with a [0..1] cardinality instead of 0.
By the way the generation is tuned with <xjc:treatRestrictionLikeNewType / so that a XSD restriction is not mapped to a Java class inheritance.
Here is an example:
Here is the way a field is defined in a complex type A:
<element name="qualifier" type="CR" maxOccurs="unbounded" minOccurs="0"/
Here is the way the same field is restricted in another complex type B that restricts A:
<element name="qualifier" type="CR" minOccurs="0" maxOccurs="0"/
In the A generated class I have:
@XmlElement(name = "qualifier")
protected List<CR qualifiers;
And in the B generated class I have:
protected CR qualifiers;
With my poor understanding of JAXB the absence of the XmlElement annotation tells JAXB not to marshall/unmarshall this field. Am I wrong?
If I am right is there a way to tell JAXB not to generate the qualifiers field at all?
This would be in my opinion a much better generation as it respects the constraints.
Any idea, thougths on the topic?
Thanks!!