Community
Participate
Working Groups
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 ?
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.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink