Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 358299 - XmlAnyElement produces duplicate namespace declarations when marshalling
Summary: XmlAnyElement produces duplicate namespace declarations when marshalling
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-20 16:07 EDT by Rick Barkhouse CLA
Modified: 2022-06-09 10:30 EDT (History)
1 user (show)

See Also:


Attachments
proposed fix and test (9.10 KB, patch)
2011-09-22 15:09 EDT, Matt MacIvor CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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