Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 358299

Summary: XmlAnyElement produces duplicate namespace declarations when marshalling
Product: z_Archived Reporter: Rick Barkhouse <rick.barkhouse>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: matt.macivor
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
proposed fix and test none

Description Rick Barkhouse CLA 2011-09-20 16:07:10 EDT
When marshalling an object containing an XmlAnyElement, and using element-form-default="QUALIFIED", duplicate namespace declarations are written out.

Consider the following Java classes / XML Bindings file:

=====

[package-info.java]
@XmlSchema(elementFormDefault=XmlNsForm.QUALIFIED)
package namespaces;

[CustomerAnno.java]
@XmlRootElement
public class CustomerAnno {
    @XmlAnyElement
    public Object anyElem;
}

=====

    <xml-schema element-form-default="QUALIFIED"/>

    <java-types>
        <java-type name="Customer">
            <xml-root-element />
            <java-attributes>
                <xml-any-element java-attribute="anyElem" />
            </java-attributes>
        </java-type>
    </java-types>

=====

If a namespace-qualified Element is set on anyElem:

anyElem = doc.createElementNS("any-element", "my-elem");

Upon marshalling:

Anno: class org.eclipse.persistence.jaxb.JAXBContext
<?xml version="1.0" encoding="UTF-8"?>
<customerAnno xmlns="http://www.example.org/root" xmlns:ns1="http://www.example.org/property" xmlns:ns0="http://www.example.org/type" id="0">
   <my-elem xmlns="any-element" xmlns="any-element"/>
</customerAnno>

OXM: class org.eclipse.persistence.jaxb.JAXBContext
<?xml version="1.0" encoding="UTF-8"?>
<customer xmlns="http://www.example.org/root" xmlns:ns1="http://www.example.org/property" xmlns:ns0="http://www.example.org/type" ns0:id="0">
   <my-elem xmlns="any-element" xmlns="any-element"/>
</customer>

   * Note duplicate declaration of 'any-element'


Also note that our formatting of the my-elem element is different from the RI's:

Anno: class com.sun.xml.bind.v2.runtime.JAXBContextImpl
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:customerAnno xmlns="http://www.example.org/type" xmlns:ns2="http://www.example.org/property" xmlns:ns3="http://www.example.org/root" id="0">
    <my-elem:my-elem xmlns:my-elem="any-element" xmlns="any-element"/>
</ns3:customerAnno>
Comment 1 Matt MacIvor CLA 2011-09-22 15:09:09 EDT
Created attachment 203859 [details]
proposed fix and test
Comment 2 Matt MacIvor CLA 2011-09-27 13:02:39 EDT
Attached patch checked in to SVN
Reviewed by Denise Smith
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:30:19 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink