Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 493237 - JSON_WRAPPER_AS_ARRAY_NAME property doesn't work with @XmlElementRef
Summary: JSON_WRAPPER_AS_ARRAY_NAME property doesn't work with @XmlElementRef
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-09 08:41 EDT by Joachim Kanbach CLA
Modified: 2022-06-09 10:07 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joachim Kanbach CLA 2016-05-09 08:41:24 EDT
I'd like to use a JAXB mapping like this:

@XmlElementWrapper( name = "value" )
@XmlElementRef
private Collection<? extends Supertype> collection;

I need to use @XmlElementRef instead of @XmlElement because there are many different sub types extending the class I named "Supertype" here, and I don't want to use the xsi:type feature for inheritance, respectively the "type" attribute for JSON.

If I use @XmlElement instead, the resulting JSON looks like this:

"value": [ {"type": "someSubtype", "id": [...]} ]

So in this case, JSON_WRAPPER_AS_ARRAY_NAME works as expected.

With @XmlElementRef, the result looks like this:

"value": {"someSubtype": [ {"id": [...]} ] }

So I get the name of the referred element as an additional wrapper around the array, which corresponds to the description of JSON_WRAPPER_AS_ARRAY_NAME being set to false, here: http://www.eclipse.org/eclipselink/api/2.5/org/eclipse/persistence/jaxb/MarshallerProperties.html#JSON_WRAPPER_AS_ARRAY_NAME

Instead, I'd expect the result to be

"value": { [ {"id": [...]} ] }

Maybe this bug is related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=410095 ?
Comment 1 Joachim Kanbach CLA 2016-05-10 10:35:53 EDT
According to an answer by Blaise Doughan on Stack Overflow (http://stackoverflow.com/questions/22500636/jaxb-and-moxy-xml-and-json-marshalling-of-generic-list-in-jersey/22502193#22502193), what I witnessed might be intended behaviour. Quoting from his answer and applying it to my situation, the question seems to be if the item name is significant in a case where the type is a bounded wildcard type.
Comment 2 Eclipse Webmaster CLA 2022-06-09 10:07:20 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink