Michael Borgwardt said:
May be a bug in JAXB, may be a restriction in JAXB (probably specific features,
rather than general complexity), may be an error in the schema itself.
We can't tell without seeing details.
Right!
ok, details...
I tried to isolate the problem, and it looks like a parsing lack, due to the
particular type of language (LR2 ?) defined in my xml schema.
So, that's my schema:
<xs:schema xmlns:xs="
http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Parent">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element name="Child1" type="xs:string"/>
<xs:element ref="Child2" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
<xs:element ref="Child2" maxOccurs="unbounded"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="Child2" type="xs:string"/>
</xs:schema>
I try to create the XML output:
<Parent >
<Child1>String</Child1>
<Child2>String</Child2>
<Child2>String</Child2>
</Parent>
That's the code:
...
ObjectFactory of = new ObjectFactory();
Parent p = of.createParent();
p.setChild1("child1 name1");
Child2 c2 = of.createChild2("Child2 1");
p.getChild2().add(c2);
Child2 c2_2 = of.createChild2("Child2 2");
p.getChild2().add(c2_2);
JAXBContext jc = JAXBContext.newInstance("myPackage");
Marshaller m = jc.createMarshaller();
m.marshal(p, System.out);
...
The exception is:
DefaultValidationEventHandler: [ERROR]: myPackage.impl.Child2Impl
Location: obj: myPackage.impl.ParentImpl@7
com.sun.xml.bind.serializer.AbortSerializationException:
myPackage.impl.Child2Impl
....
....
--------------- linked to ------------------
javax.xml.bind.MarshalException
- with linked exception:
[com.sun.xml.bind.serializer.AbortSerializationException:
myPackage.impl.Child2Impl]
I think the problem is that the parser cannot distinguish if a Child2
instance belongs to the first or to the second branch of the Parent
hierarchy in the schema.
Hope it helps to understand the problem, so you can help me
Ciao
Marcello