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

Bug 353043

Summary: Type-level namespace dec. not working in XML Bindings
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: blaise.doughan
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Work in progress
none
Patch - 2.4
none
Patch - 2.3
none
Patch - 2.3
none
Patch - 2.4 none

Description Rick Barkhouse CLA 2011-07-25 16:06:55 EDT
Considering the following annotated Customer and package-info classes:

--------------------

@XmlSchema(
    namespace = "http://www.example.org/package",
    elementFormDefault = XmlNsForm.QUALIFIED)
package documentation;
 
import javax.xml.bind.annotation.XmlNsForm;

--------------------

package documentation;

import javax.xml.bind.annotation.*;

@XmlRootElement
@XmlType(namespace="http://www.example.org/type")
public class Customer {
    public String name;
}

--------------------

Marshalling an example object would look like this:

<?xml version="1.0" encoding="UTF-8"?>
<customer xmlns="http://www.example.org/package"
   xmlns:ns0="http://www.example.org/type">
   <ns0:name>Bob</ns0:name>
</customer>

- customer has "package" namespace
- name has "type" namespace (inherited from Customer type)

====================

The equivalent XML Bindings file should look like this:

<?xml version="1.0" encoding="US-ASCII"?>
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    package-name="documentation">

    <xml-schema element-form-default="QUALIFIED"
        namespace="http://www.example.org/package">
    </xml-schema>

    <java-types>
        <java-type name="Custom">
            <xml-root-element />
            <xml-type namespace="http://www.example.org/type" />
            <java-attributes>
                <xml-element java-attribute="name" />
            </java-attributes>
        </java-type>
    </java-types>

</xml-bindings>

Now when marshalling, even though the "type" namespace is defined, it is not used on the "name" element:

<?xml version="1.0" encoding="UTF-8"?>
<custom xmlns="http://www.example.org/package" xmlns:ns0="http://www.example.org/type">
   <name>Bob</name>
</custom>
Comment 1 Rick Barkhouse CLA 2011-09-12 14:18:35 EDT
Created attachment 203179 [details]
Work in progress
Comment 2 Rick Barkhouse CLA 2011-09-16 16:15:16 EDT
Created attachment 203526 [details]
Patch - 2.4
Comment 3 Rick Barkhouse CLA 2011-09-16 16:16:08 EDT
Created attachment 203527 [details]
Patch - 2.3
Comment 4 Rick Barkhouse CLA 2011-09-21 14:14:40 EDT
During review it was uncovered that the same problem exists for XmlAttributes.
Comment 5 Rick Barkhouse CLA 2011-09-21 14:16:44 EDT
Created attachment 203796 [details]
Patch - 2.3
Comment 6 Rick Barkhouse CLA 2011-09-21 14:16:58 EDT
Created attachment 203797 [details]
Patch - 2.4
Comment 7 Rick Barkhouse CLA 2011-09-22 10:23:45 EDT
Fixed and checked in to 2.3.1 and 2.4, reviewed by bdoughan and dmahar.

New test case: org.eclipse.persistence.testing.jaxb.externalizedmetadata.namespace.NamespaceTestCases
Comment 8 Rick Barkhouse CLA 2011-09-22 10:24:19 EDT
Resolved.
Comment 9 Eclipse Webmaster CLA 2022-06-09 10:35:17 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink