Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 353042 - Setting attributeFormDefault=QUALIFIED on @XmlSchema prevents default namespace being used for elements
Summary: Setting attributeFormDefault=QUALIFIED on @XmlSchema prevents default namespa...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 normal with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Blaise Doughan CLA
QA Contact:
URL: http://stackoverflow.com/questions/68...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-25 16:04 EDT by Blaise Doughan CLA
Modified: 2022-06-09 10:08 EDT (History)
2 users (show)

See Also:


Attachments
Proposed changes (37.60 KB, patch)
2013-02-08 10:50 EST, Denise Smith CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Blaise Doughan CLA 2011-07-25 16:04:11 EDT
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>
Comment 1 Denise Smith CLA 2011-09-15 13:20:28 EDT
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>
Comment 2 Blaise Doughan CLA 2012-05-24 10:39:00 EDT
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>
Comment 3 Denise Smith CLA 2013-02-08 10:50:38 EST
Created attachment 226785 [details]
Proposed changes
Comment 4 Denise Smith CLA 2013-02-08 10:56:54 EST
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.
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:08:36 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink