Community
Participate
Working Groups
Given the following class: import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement; import org.eclipse.persistence.oxm.annotations.XmlPath; @XmlRootElement public class FooBar { @XmlAttribute @XmlPath("test/@foo") private boolean foo; } The following incorrect schema is generated: <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:ns0="http://moxy.test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://moxy.test" elementFormDefault="qualified"> <xsd:complexType name="fooBar"> <xsd:sequence> <xsd:element name="test" minOccurs="0"> <xsd:complexType> <xsd:sequence/> <xsd:attribute ref="ns0:foo"/> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> <xsd:element name="fooBar" type="ns0:fooBar"/> <xsd:attribute name="foo" type="xsd:boolean" use="required"/> </xsd:schema> WORKAROUND: If we remove the @XmlAttribute Annotation: import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement; import org.eclipse.persistence.oxm.annotations.XmlPath; @XmlRootElement public class FooBar { //@XmlAttribute @XmlPath("test/@foo") private boolean foo; } Then the correct XML schema is generated: class org.eclipse.persistence.jaxb.JAXBContext <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:ns0="http://moxy.test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://moxy.test" elementFormDefault="qualified"> <xsd:complexType name="fooBar"> <xsd:sequence> <xsd:element name="test" minOccurs="0"> <xsd:complexType> <xsd:sequence> <xsd:element name="@foo" type="xsd:boolean"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> <xsd:element name="fooBar" type="ns0:fooBar"/> </xsd:schema>
Created attachment 201078 [details] Code demonstrating the bug
CORRECTION The workaround is not valid as it produces: <xsd:element name="@foo" type="xsd:boolean"/>
Created attachment 201098 [details] Proposed changes and tests
Fixed in 2.3 and 2.4. Modified AnnotationsProcessor - the processing of XmlPath annotation was not allowing for the XmlPath to be to an attribute. Also changed behavior so that if an @XmlAttribute was specified by the XmlPath was to an element the XmlPath annotation "wins".
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink