users@jersey.java.net

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

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Wed, 12 Nov 2008 12:46:26 -0800

Hi Jeremy,

On Wed, Nov 12, 2008 at 10:45:05AM -0800, Jeremy Whitlock wrote:
> Hi All,
> I've been trying to figure out a good way to return both JSON
> and XML for my resources. Based on the examples, it's easy but I have a
> little nit that I'd like to solve. Whenever my resource returns a
> collection, List<Person> for example, the roots for the XML/JSON is
> never what I want it to be. For XML, I end up with "People" as the root
> and with JSON, I get "person". As you can see, XML automatically
> capitalizes the root node and with JSON, the "root" isn't pluralized.
> I'm using the usual JAXB annotations and using jersey-json to do the
> JAXB->JSON stuff but I've done anything custom. So...here are my two
> questions:
>
> 1) Can Jersey be made to handle it properly so that both XML and JSON
> end up with the same root? (So instead of "People" and "person", I get
> "people"?)

In this case i would like to see Jersey generating JSON array
instead of JSON object for java collections. Then the root element would not
exist. Would this approach work for you?


> 2) If not, what options do I have to get this more like I want it?

I will need to have a more detailed look into this case.
(Attending a conference and do not have much time for it this week).
Please feel free to file a RFE at [1], so that i can keep track on it.

>
> I don't mind having to do the XML and JSON myself using utility classes
> or something but with Jersey providing so much, I figured I'd get some
> advice before writing more generic serializers.


I will be happy to update current JSON functionality to better suit your needs,
so there is no need for you to add special utilities to your application for this.

~Jakub



>
> Take care,
>
> Jeremy Whitlock | Software Engineer | CollabNet, Inc.
> 8000 Marina Blvd. Suite 600 | Brisbane, CA 94005 | USA
> O 650.228.2516 | C 970.988.8822 | jwhitlock_at_collab.net
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>