Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 355261 - Namespace Issue with TypeMappingInfo wrapping Object
Summary: Namespace Issue with TypeMappingInfo wrapping Object
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: Denise Smith CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-19 15:23 EDT by Matt MacIvor CLA
Modified: 2022-06-09 10:02 EDT (History)
2 users (show)

See Also:


Attachments
New Test reproducing this issue (7.96 KB, patch)
2011-09-16 15:38 EDT, Denise Smith CLA
no flags Details | Diff
Proposed changes and test (10.80 KB, patch)
2011-09-19 10:47 EDT, Denise Smith CLA
no flags Details | Diff
Additional changes and tests (21.27 KB, patch)
2011-09-19 15:15 EDT, 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 Matt MacIvor CLA 2011-08-19 15:23:18 EDT
Given the following Employee class:
@XmlType(name="employee", namespace="someuri")
public class Employee {

    public String name;
    
    public String id;
    
    public boolean equals(Object obj) {
        return name.equals(((Employee)obj).name) && id.equals(((Employee)obj).id);
    }
}

Create a context using TypeMappingInfos, with one based on Object (for Polymorphism)

        TypeMappingInfo[] typeMappingInfos = new TypeMappingInfo[2];
        
        TypeMappingInfo tpi = new TypeMappingInfo();
        tpi.setXmlTagName(new QName("someuri","response"));       
        tpi.setElementScope(ElementScope.Global);
        tpi.setType(Object.class);
        typeMappingInfos[0] = tpi;        
        
        TypeMappingInfo tmi = new TypeMappingInfo();
        tmi.setType(Employee.class);
        tmi.setXmlTagName(new QName("someuri", "employee"));
        tmi.setElementScope(ElementScope.Global);
        typeMappingInfos[1] = tmi;
        
        JAXBContext ctx = JAXBContextFactory.createContext(typeMappingInfos, null, Thread.currentThread().getContextClassLoader());

Create the following JAXBElement, and marshal using the TypeMappingInfo wrapping Object. (The marshal will work fine without the TMI or with the one for Employee, but should also work for the one wrapping object)

        Employee emp = new Employee();
        emp.id = "123";
        emp.name="aaa";
        JAXBElement<Object> elem = new JAXBElement<Object>(new QName("someuri", "response"), Object.class, emp);
        ((JAXBMarshaller)ctx.createMarshaller()).marshal(elem, new StreamResult(System.out), tpi);

Observe the output XML:

<ns1:response xmlns:ns1="someuri" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns0:employee">
   <name>aaa</name>
   <id>123</id>
</ns1:response>

The xsi:type references "ns0:employee", but ns0 is never declared.
Comment 1 Denise Smith CLA 2011-09-16 15:38:55 EDT
Created attachment 203521 [details]
New Test reproducing this issue
Comment 2 Denise Smith CLA 2011-09-19 10:47:16 EDT
Created attachment 203600 [details]
Proposed changes and test
Comment 3 Denise Smith CLA 2011-09-19 15:15:38 EDT
Created attachment 203623 [details]
Additional changes and tests
Comment 4 Denise Smith CLA 2011-09-20 10:42:50 EDT
Fixed in MappingsGenerator to track generated prefix/uri pairs in the globalnamespaceresolver and re use when possible.

Also modified XMLOBjectBuilder to update the value of the type indicator field if possible to use the prefix from the row.
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:02:33 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink