Community
Participate
Working Groups
EclipseLink JAXB (MOXy) is handling the prefix qualification for elements differently depending upon the attribute form qualification (as demonstrated below). **A** package forum6808921; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class A { private String b; public String getB() { return b; } public void setB(String b) { this.b = b; } } **Demo** package forum6808921; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(A.class); A a = new A(); a.setB("Hello World"); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(a, System.out); } } **package-info without attributeFormDefault set** @XmlSchema( namespace = "sample.com/x" , elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED ) package forum6808921; import javax.xml.bind.annotation.*; ***Output:*** <?xml version="1.0" encoding="UTF-8"?> <a xmlns="sample.com/x"> <b>Hello World</b> </a> **package-info with attributeFormDefault set** @XmlSchema( namespace = "sample.com/x" , elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED , attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED ) package forum6808921; import javax.xml.bind.annotation.*; ***Output:*** <?xml version="1.0" encoding="UTF-8"?> <ns0:a xmlns:ns0="sample.com/x"> <ns0:b>Hello World</ns0:b> </ns0:a>
This currently behaves the same as the RI so may not be an issue. See output below: OUTPUT WITH PACKAGE INFO elementFormDefault=QUALIFIED, attriubteform not set class com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <a xmlns="sample.com/x" c="Hello World"> <b>Hello World</b> </a> class org.eclipse.persistence.jaxb.JAXBContext <?xml version="1.0" encoding="UTF-8"?> <a xmlns="sample.com/x" c="Hello World"> <b>Hello World</b> </a> OUTPUT WITH PACKAGE INFO elementFormDefault=QUALIFIED, attriubteform=QUALIFIED class com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ns1:a xmlns:ns1="sample.com/x" ns1:c="Hello World"> <ns1:b>Hello World</ns1:b> </ns1:a> class org.eclipse.persistence.jaxb.JAXBContext <?xml version="1.0" encoding="UTF-8"?> <ns0:a xmlns:ns0="sample.com/x" ns0:c="Hello World"> <ns0:b>Hello World</ns0:b> </ns0:a>
Using JDK 1.7.0 (for Mac) the output using MOXy is different from the JAXB RI. <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <a xmlns="sample.com/x"> <b>Hello World</b> </a> <?xml version="1.0" encoding="UTF-8"?> <ns0:a xmlns:ns0="sample.com/x"> <ns0:b>Hello World</ns0:b> </ns0:a>
Created attachment 226785 [details] Proposed changes
Attached patch checked in to 2.4 and trunk. In the example given here MOXy behaves differently than the RI as Blaise shows. That has been fixed with the attached patch. However in the same case if there actually is an @XmlAttribute annotation on b then we match the RI behavior to fully qualify and not use the defaultnamespace. We used to disallow the use of default namespace if the attributeFormDefault was set to qualified but now only disallow it if it is set to qualified AND there are @XmlAttribute annotations. A new bug has been opened to track the case where we could possibly do different than the RI and allow the default namespace even if there is an @XmlAttribute annotation. See bug 400329.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink