I want to generate classes using maven-jaxb2-plugin.
My input xsd looks like the following:
<complexType>
<complexContent>
<restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
<sequence>
<element name="ReferencedElementA" type="{http://www.w3.org/2001/XMLSchema}IDREFS" minOccurs="0" />
<element name="ReferencedElementB" type="{http://www.w3.org/2001/XMLSchema}IDREF"
maxOccurs="unbounded" minOccurs="0" />
</sequence>
</restriction>
</complexContent>
Please note, that i can't alter the schema as it is provided by an external customer!
This is the generated code:
@XmlList
@XmlElement(name = "ReferencedElementA")
@XmlIDREF
@XmlSchemaType(name = "IDREFS")
protected List<Object> referencedElementA;
@XmlElementRef(name = "ReferencedElementB", namespace = "ABC", type = JAXBElement.class, required = false)
protected List<JAXBElement<Object>> referencedElementB;
As you see, the "ReferencedElementB" is generated as a List> with the @XMLElementRef-Annotation.
What i want, is something like the following:
@XmlElement(name = "ReferencedElementB")
@XmlIDREF
@XmlSchemaType(name = "IDREF")
protected List<Object> referencedElementB;
Using the workaround from Blaise Doughan, i expanded my binding file with the following code:
<bindings node = ".//xs:element[@name='ReferencedElementB']">
<class ref="java.lang.Object"/>
</bindings>
This almost finished the job, generating code like this:
@XmlElement(name = "ReferencedElementB")
@XmlSchemaType(name = "IDREF")
protected List<Object> referencedElementB;
However, the @XmlIDREF-Annotation is still missing. This produces errors during marshalling.
I've tried to inject the missing annotation via annox-plugin:
<bindings node = ".//xs:element[@name='ReferencedElementB']">
<class ref="java.lang.Object"/>
<annox:annotate target="field">@javax.xml.bind.annotation.XmlIDREF</annox:annotate>
</bindings>
But the generation fails with
compiler was unable to honor this annox:annotate customization. It is attached to a wrong place, or its inconsistent with other bindings
Once again, i'm not able to alter the input xsd.
Thank you in advance!