Community
Participate
Working Groups
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.
Created attachment 203521 [details] New Test reproducing this issue
Created attachment 203600 [details] Proposed changes and test
Created attachment 203623 [details] Additional changes and tests
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.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink