Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 353043 - Type-level namespace dec. not working in XML Bindings
Summary: Type-level namespace dec. not working in XML Bindings
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-07-25 16:06 EDT by Rick Barkhouse CLA
Modified: 2022-06-09 10:35 EDT (History)
1 user (show)

See Also:


Attachments
Work in progress (16.42 KB, patch)
2011-09-12 14:18 EDT, Rick Barkhouse CLA
no flags Details | Diff
Patch - 2.4 (10.99 KB, patch)
2011-09-16 16:15 EDT, Rick Barkhouse CLA
no flags Details | Diff
Patch - 2.3 (10.91 KB, patch)
2011-09-16 16:16 EDT, Rick Barkhouse CLA
no flags Details | Diff
Patch - 2.3 (13.02 KB, patch)
2011-09-21 14:16 EDT, Rick Barkhouse CLA
no flags Details | Diff
Patch - 2.4 (13.02 KB, patch)
2011-09-21 14:16 EDT, Rick Barkhouse 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-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