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

Bug 340673

Summary: Unexpected JAXBElement returned when unmarshalling with inheritance / XmlSeeAlso
Product: z_Archived Reporter: Rick Barkhouse <rick.barkhouse>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P2 CC: blaise.doughan, david.twelves, prabaharan.vijayaratnam
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
testmodel and testcase to reproduce the bug
none
testmodel and testcase to reproduce the bug
none
testmodel and testcase to reproduce the bug
none
testcase to reproduce the bug
none
MOXy - Test Cases
none
MOXy - Test Cases
none
MOXy - Test Cases none

Description Rick Barkhouse CLA 2011-03-22 11:34:37 EDT
Consider the following classes:

-----

@XmlRootElement
@XmlSeeAlso({Dog.class, Cat.class})
public class Animal {
    public String name;
}

@XmlRootElement
public class Cat extends Animal {
    public int sleepTime;
    public Dog enemy;
}

public class Dog extends Animal {
    public String barkLevel;
}

-----

And the following instance document:

-----

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<animal xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="cat">
    <name>Fluffy</name>
    <sleepTime>10</sleepTime>
    <enemy>
        <name>Buster</name>
        <barkLevel>LOUD</barkLevel>
    </enemy>
</animal>

-----

When this document is unmarshalled using MOXy, a JAXBElement is returned, however the RI will unmarshal this as a true Cat object.
Comment 1 Rick Barkhouse CLA 2011-03-22 11:39:18 EDT
This bug is captured in the following test case:

org.eclipse.persistence.testing.jaxb.javadoc.xmlseealso.XmlSeeAlsoTest

(Praba is working on these tests and they have not been checked in yet, the above test class name may change)
Comment 2 Praba Vijayaratnam CLA 2011-04-28 11:16:30 EDT
While I was trying out JDK6-JAXB annotation examples, I got few failures with
XmlSeeAlso example.
EclipseLink build: 2.3.0 (April 23)
JDK: 1.6.0_20


Test Class:
org.eclipse.persistence.testing.jaxb.javadoc.xmlseealso.XmlSeeAlsoTest

Following unmarshall tests failed:
---------------------
Java Project Source w/SAX Parsing: XmlSeeAlsoTes:
testXMLToObjectFromInputStream
Java Project Source w/SAX Parsing: XmlSeeAlsoTes:
testRoundTrip
Java Project Source w/SAX Parsing: XmlSeeAlsoTes:
testXMLToObjectFromURL
Java Project Source w/SAX Parsing: XmlSeeAlsoTes:
testXMLToObjectFromXMLStreamReader
Java Project Source w/SAX Parsing: XmlSeeAlsoTes:
testXMLToObjectFromXMLEventReader
Java Project Source w/SAX Parsing: XmlSeeAlsoTes:
testUnmarshallerHandler

Stack trace were similar to following:
---------------------------------------
junit.framework.AssertionFailedError:
expected:<org.eclipse.persistence.testing.jaxb.javadoc.xmlseealso.Cat@2fa918d5>
but was:<javax.xml.bind.JAXBElement@49bdc9d8>
    at junit.framework.Assert.fail(Assert.java:47)
    at junit.framework.Assert.failNotEquals(Assert.java:283)
    at junit.framework.Assert.assertEquals(Assert.java:64)
    at junit.framework.Assert.assertEquals(Assert.java:71)
    at
org.eclipse.persistence.testing.oxm.mappings.XMLMappingTestCases.xmlToObjectTest(XMLMappingTestCases.java:269)
    at
org.eclipse.persistence.testing.jaxb.JAXBTestCases.xmlToObjectTest(JAXBTestCases.java:430)
    at
org.eclipse.persistence.testing.jaxb.JAXBTestCases.testXMLToObjectFromInputStream(JAXBTestCases.java:169)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
Comment 3 Praba Vijayaratnam CLA 2011-04-28 11:17:38 EDT
*** Bug 344057 has been marked as a duplicate of this bug. ***
Comment 4 Praba Vijayaratnam CLA 2011-05-03 15:17:44 EDT
Created attachment 194631 [details]
testmodel and testcase to reproduce the bug
Comment 5 Praba Vijayaratnam CLA 2011-05-03 15:19:15 EDT
Created attachment 194633 [details]
testmodel and testcase to reproduce the bug
Comment 6 Praba Vijayaratnam CLA 2011-05-03 15:20:29 EDT
Created attachment 194634 [details]
testmodel and testcase to reproduce the bug
Comment 7 Praba Vijayaratnam CLA 2011-05-03 15:21:25 EDT
Created attachment 194635 [details]
testcase to reproduce the bug
Comment 8 Blaise Doughan CLA 2012-05-24 15:38:26 EDT
Created attachment 216230 [details]
MOXy - Test Cases
Comment 9 Blaise Doughan CLA 2012-05-24 16:14:32 EDT
Created attachment 216235 [details]
MOXy - Test Cases
Comment 10 Blaise Doughan CLA 2012-05-24 16:17:14 EDT
Created attachment 216236 [details]
MOXy - Test Cases
Comment 11 Blaise Doughan CLA 2012-05-24 16:29:16 EDT
Fix checked into 2.4.0 at revision:  11488
Fix checked into trunk at revision:  11489


Code reviewed by:  Rick Barkhouse

---

Resolution

There is a difference in how MOXy and the RI handle this use case.  As MOXy is able to round trip the following document and the RI is not, I believe the MOXy behaviour to be the correct behaviour for this use case.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<animal xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="cat">
    <name>Fluffy</name>
    <sleepTime>10</sleepTime>
    <enemy>
        <name>Buster</name>
        <barkLevel>LOUD</barkLevel>
    </enemy>
</animal>

Note both MOXy and the RI handle the following document the same:

<cat>
    <name>Fluffy</name>
    <sleepTime>10</sleepTime>
    <enemy>
        <name>Buster</name>
        <barkLevel>LOUD</barkLevel>
    </enemy>
</cat>
Comment 12 Eclipse Webmaster CLA 2022-06-09 10:33:40 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink