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

Bug 350626

Summary: Error when XmlAdapter is used with Generics
Product: z_Archived Reporter: Blaise Doughan <blaise.doughan>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: matt.macivor
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
URL: http://stackoverflow.com/questions/6362684/nested-xmljavatypeadapter-annotations-ignored-where-nested-objects-are-generic-w
Whiteboard:
Attachments:
Description Flags
Proposed Fix and Test Cases none

Description Blaise Doughan CLA 2011-06-28 15:05:29 EDT
Steps to reproduce issue:

**Root**

    package example;

    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
    
    @XmlRootElement
    public class Root {
    
        @XmlJavaTypeAdapter(AAdapter.class)
        public A<B> a;
    
    }

**A**

    package example;

    public class A<T> {
    
        public T t;
    
    }

**AAdapter**

    package example;

    import javax.xml.bind.annotation.adapters.XmlAdapter;
    
    public class AAdapter<T> extends XmlAdapter<T, A<T>> {
    
        @Override
        public A<T> unmarshal(T v) throws Exception {
            return new A<T>();
        }
    
        @Override
        public T marshal(A<T> v) throws Exception {
            return v.t;
        }
    
    }

**B**

    package example;

    public class B {
    
    }

**Demo**

    package example;

    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.Marshaller;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance(Root.class, B.class);
    
            Root root = new Root();
            A<B> a = new A<B>();
            a.t = new B();
            root.a = a;
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(root, System.out);
        }
    
    }

**Output**

    <?xml version="1.0" encoding="UTF-8"?>
    <root>
       <a>example.B@3ecfff</a>
    </root>

**Expected Output**

    <?xml version="1.0" encoding="UTF-8"?>
    <root>
        <a xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="b"/>
    </root>
Comment 1 Matt MacIvor CLA 2011-07-07 14:54:50 EDT
Created attachment 199285 [details]
Proposed Fix and Test Cases
Comment 2 Matt MacIvor CLA 2011-09-16 14:37:08 EDT
Attached patch has been checked in to SVN
Reviewed by Blaise Doughan.
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:14:46 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:18:56 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink