Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 340673 - Unexpected JAXBElement returned when unmarshalling with inheritance / XmlSeeAlso
Summary: Unexpected JAXBElement returned when unmarshalling with inheritance / XmlSeeAlso
Status: RESOLVED INVALID
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 344057 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-03-22 11:34 EDT by Rick Barkhouse CLA
Modified: 2022-06-09 10:33 EDT (History)
3 users (show)

See Also:


Attachments
testmodel and testcase to reproduce the bug (1.36 KB, application/octet-stream)
2011-05-03 15:17 EDT, Praba Vijayaratnam CLA
no flags Details
testmodel and testcase to reproduce the bug (1.10 KB, application/octet-stream)
2011-05-03 15:19 EDT, Praba Vijayaratnam CLA
no flags Details
testmodel and testcase to reproduce the bug (1.11 KB, application/octet-stream)
2011-05-03 15:20 EDT, Praba Vijayaratnam CLA
no flags Details
testcase to reproduce the bug (1.41 KB, application/octet-stream)
2011-05-03 15:21 EDT, Praba Vijayaratnam CLA
no flags Details
MOXy - Test Cases (7.24 KB, patch)
2012-05-24 15:38 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Test Cases (7.26 KB, patch)
2012-05-24 16:14 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Test Cases (7.28 KB, patch)
2012-05-24 16:17 EDT, Blaise Doughan 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-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