users@jersey.java.net

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

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 17 Nov 2008 11:30:21 +0100

On Nov 14, 2008, at 11:36 PM, Jeremy Whitlock wrote:

> Hello all,
> Alright, I have created a simple Jersey app that utilizes JAXB
> to take collections of objects and return a JSON/XML representation
> for
> the collections. What I found was actually pretty interesting and
> here
> is a brief summary:
>
> 1) Generic list support: While Jersey does not include an element for
> each array element, it shouldn't be necessary. (For example:
> List<Person>.)
> 2) Array support: Jersey seemed to have a problem taking an array of
> objects and serializing them to JSON/XML. I kept getting errors about
> no content writer being available. (For example: Person[].)

It is currently not supported, although it would be easy to add. Only
List<?> or a sub type of is supported for writing. And Collection<?>
or List<?> for reading.

Paul.

>
> 3) Mixed list support: Same as scenario #2. No content writer
> available.
>
> With regard to scenarios #2, if I return a single object instead of an
> array of objects, the serialization works fine so JAXB should be
> able to
> serialize an array of objects all the same type.
>
> Attached is the sample Maven project that demonstrates this
> functionality. To see an example of the output, just run "mvn compile
> exec:java" and you'll get some output to view for relating to this
> thread's discussion. (When running the example, you'll see that the
> accesses for places.json and places.xml are commented out because they
> just don't work.) There is a lot of code duplication since I was
> having
> a problem getting a Resource to serialize properly. (I emailed this
> list about this already.) I also know this could had been done using
> unit tests but sometimes, seeing is believing.
>
> Take care,
>
> Jeremy
>
> <jersey-serializers-
> example
> .zip
> >---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net