users@jersey.java.net

Re: [Jersey] Set the root when returning a collection

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 13 Nov 2008 09:52:08 +0100

On Nov 12, 2008, at 11:05 PM, Jeremy Whitlock wrote:

>> Just curious if you have only one person item in your array.
>
> No. I had 3 items in the array, each fully initialized so that all
> member variables were non-null. The actual type being serialized was
> List<Person>, which behind the scenes was ArrayList<Person>.
>
>> By default the JSON support always strips out the root element, so it
>> is never encoded in JSON.
>
> That's what I'm wondering...can we make it configurable with a
> property
> or something.

Yes, it is a bug. The JSON list writer is not checking the
configuration properties of the JSON specific marshaler if utilized
via the JSONJAXBContext [1].


> I think readability is adversely affected, or it can be
> depending on who the reader is. ;) Regardless, assuming one way or
> another is just begging for at least someone to get upset.
>

:-) agreed what we are finding from the JSON feedback is that
developers want to customize, but we can also greatly improve the out-
of-the-box configuration to reduce customization.


> I also think that the side effect related to XML is a good candidate
> for
> a configurable property. Assuming that the root node should be
> capitalized might not fly with everyone.
>

Agreed, plus english is not the only language (even if XML 1.0 some
what restricts the unicode characters in XML element and attribute
names). My assumption was that developers could specifically customize
by creating a wrapping JAXB bean, but i think there are configuration
options that can equally apply here to.

Paul.

[1] https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0/api/jersey/com/sun/jersey/api/json/JSONJAXBContext.html