users@jersey.java.net

Using XmlElementWrapper/XmlElement for collections breaks JSON formatting

From: Scott Haynie <Scott.Haynie_at_dreamworks.com>
Date: Tue, 12 Oct 2010 08:40:20 -0700

  I wanted to resurrect the thread about getting JSON output for
lists/arrays to look right:
https://jersey.dev.java.net/servlets/ReadMsg?list=users&msgNo=6480

My requirement is simple: I'd like my JAXB Beans (auto-generated from an
XSD) to be output as XML or JSON.

Problem is with the collections/arrays handling. In order to have
proper nesting in XML, I use @XmlElementWrapper/_at_XmlElement on my JAXB:

    @XmlElementWrapper(name = "values")
    @XmlElement(name = "value")
    protected List<String> myValues;

This allows the XML to look like this:

<values>
<value>foo</value>
<value>bar</value>
</values>

When this is formatted as JSON, I would like this to be a simple JSON
array (essentially ignore XmlElementWrapper/XmlElement):
{"values":["foo", bar"]}

But instead, it gives me this (with the NATURAL configuration):
{"values":[{"value":"foo", "value":"bar"}]}

This format is much more difficult to deal with for clients, and almost
makes the service non-usable for complex, nested schemas (ex. maps of
maps, lists of lists, etc.).

Any hope of providing this anytime soon?