Community
Participate
Working Groups
Given the following model class: @XmlRootElement(name="my-foo") public class Foo { @XmlElementRefs({ @XmlElementRef(name="a"), @XmlElementRef(name="b") }) public List<Object> stuff; } And ObjectFactory: @javax.xml.bind.annotation.XmlRegistry public class ObjectFactory { @javax.xml.bind.annotation.XmlElementDecl(name="a") public javax.xml.bind.JAXBElement<String> createA() { return new javax.xml.bind.JAXBElement<String>( new javax.xml.namespace.QName("a"), String.class, ""); } @javax.xml.bind.annotation.XmlElementDecl(name="b") public javax.xml.bind.JAXBElement<Integer> createB() { return new javax.xml.bind.JAXBElement<Integer>( new javax.xml.namespace.QName("b"), java.lang.Integer.class, 0); } } We expect the following schema to be generated: <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="foo"> <xsd:sequence> <xsd:choice maxOccurs="unbounded"> <xsd:element ref="a"/> <xsd:element ref="b"/> </xsd:choice> </xsd:sequence> </xsd:complexType> <xsd:element name="b" type="xsd:int"/> <xsd:element name="a" type="xsd:string"/> <xsd:element name="my-foo" type="foo"/> </xsd:schema> However we now get the following: <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="foo"> <xsd:sequence> <xsd:element ref="my-foo" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> <xsd:element name="b" type="xsd:int"/> <xsd:element name="a" type="xsd:string"/> <xsd:element name="my-foo" type="foo"/> </xsd:schema> Revision 8407 of AnnotationsProcessor seems to work correctly. Note that the schema is generated correctly if the type is set by either: public List<JAXBElement> stuff or @XmlElementRef(name="a" type="JAXBElement.class") The failing tests are in: org.eclipse.persistence.testing.jaxb.externalizedmetadata.xmlelementrefs.XmlElementRefsTestCases.testXmlElementRefsSchemaGen
(In reply to comment #0) > Given the following model class: > > @XmlRootElement(name="my-foo") > public class Foo { > @XmlElementRefs({ > @XmlElementRef(name="a"), > @XmlElementRef(name="b") > }) > public List<Object> stuff; > } > > And ObjectFactory: > > @javax.xml.bind.annotation.XmlRegistry > public class ObjectFactory { > @javax.xml.bind.annotation.XmlElementDecl(name="a") > public javax.xml.bind.JAXBElement<String> createA() { > return new javax.xml.bind.JAXBElement<String>( > new javax.xml.namespace.QName("a"), > String.class, > ""); > } > > @javax.xml.bind.annotation.XmlElementDecl(name="b") > public javax.xml.bind.JAXBElement<Integer> createB() { > return new javax.xml.bind.JAXBElement<Integer>( > new javax.xml.namespace.QName("b"), > java.lang.Integer.class, > 0); > } > } > > We expect the following schema to be generated: > > <?xml version="1.0" encoding="UTF-8"?> > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> > <xsd:complexType name="foo"> > <xsd:sequence> > <xsd:choice maxOccurs="unbounded"> > <xsd:element ref="a"/> > <xsd:element ref="b"/> > </xsd:choice> > </xsd:sequence> > </xsd:complexType> > <xsd:element name="b" type="xsd:int"/> > <xsd:element name="a" type="xsd:string"/> > <xsd:element name="my-foo" type="foo"/> > </xsd:schema> > > However we now get the following: > > <?xml version="1.0" encoding="UTF-8"?> > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> > <xsd:complexType name="foo"> > <xsd:sequence> > <xsd:element ref="my-foo" minOccurs="0" maxOccurs="unbounded"/> > </xsd:sequence> > </xsd:complexType> > <xsd:element name="b" type="xsd:int"/> > <xsd:element name="a" type="xsd:string"/> > <xsd:element name="my-foo" type="foo"/> > </xsd:schema> > > Revision 8407 of AnnotationsProcessor seems to work correctly. > > Note that the schema is generated correctly if the type is set by either: > > public List<JAXBElement> stuff > > or > > @XmlElementRef(name="a" type="JAXBElement.class") > > The failing tests are in: > > org.eclipse.persistence.testing.jaxb.externalizedmetadata.xmlelementrefs.XmlElementRefsTestCases.testXmlElementRefsSchemaGen In order to use the above mentioned test case(s) to verify the fix, 'type="javax.xml.bind.JAXBElement"' will have to be removed from the "a" and "b" element-ref entries in the oxm.xml file.
Created attachment 194870 [details] Proposed Fix and Updated Test
Attached patch checked in to SVN. Reviewed by Blaise Doughan
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink