Reputation: 99
I have an issue with JAXB for the following xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:complexType name="data">
<xs:sequence maxOccurs="2">
<xs:element name="indg1" type="xs:string"/>
<xs:element name="indg2" type="xs:string"/>
<xs:element name="indg3" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="sample" type="data" />
</xs:schema>
The following class is generated:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "data", propOrder = {
"indg1AndIndg2AndIndg3"
})
public class Data {
@XmlElementRefs({
@XmlElementRef(name = "indg1", type = JAXBElement.class),
@XmlElementRef(name = "indg2", type = JAXBElement.class),
@XmlElementRef(name = "indg3", type = JAXBElement.class)
})
protected List<JAXBElement<String>> indg1AndIndg2AndIndg3;
public List<JAXBElement<String>> getIndg1AndIndg2AndIndg3() {
if (indg1AndIndg2AndIndg3 == null) {
indg1AndIndg2AndIndg3 = new ArrayList<JAXBElement<String>>();
}
return this.indg1AndIndg2AndIndg3;
}
}
What I was expecting was a class by the name of "Sample" with List<Data>
.
Can you tell me how to do it, and why the behavior above is as it is?
Upvotes: 0
Views: 261
Reputation: 31290
Look into the generated class ObjectFactory. It contains a method for creating an element sample using an instance of class Data. The top level element of a document doesn't need a class of its own.
You are getting this strange List<JAXBElement<String>>
because you have a repetition of a sequence of heterogeneous elements.
Upvotes: 1