users@jersey.java.net

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

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Fri, 14 Nov 2008 11:47:11 -0800

Jeremy, please see inline...

On Fri, Nov 14, 2008 at 09:10:13AM -0800, Jeremy Whitlock wrote:
> > Fixed in the main trunk. Jersey in fact was taking the name
> > from the appropriate type and was not capitalizing it at all.
>
> Cool.
>
> > Do you mean something like:
> >
> > [{"person":{"age":"27",...}}, {"person":{"age":...}}]
> >
> > ?
> >
> > To me it seems a bit redundant, but i agree people should be able
> > to get it (but not by default)
>
> That is what I mean but I also agree that it could be redundant. If I
> saw:
>
> {'people': [{'name': ...}, {'name': ...}]}
>
> it should be easy to assume that 'people' corresponds with an array of
> people objects. In this scenario, living without more verbosity makes
> sense but what about when you have differing types of objects in a List.

in such case, you will not end up with an array, i.e.

<person><foo>bar</foo></person><person><foo>baz<</foo></person>

gets translated into (omitting quotes):

{person:[{foo:bar},{foo:baz}]}

while

<person><foo>bar</foo></person><animal><bee>cee</bee></animal>

gets translated into:

{person:{foo:bar},animal:{bee:cee}}

> I know that might be more of an edge case but without some sort of
> element name, it'd be hard to distinguish one time from another.
> (Yes...I don't see too many programmers taking a list and populating it
> with multiple types of objects so this may be moot but it's worth
> mentioning.)
>
> > >> 3) In JSON, the root is not plural.
> >
> > So that you will end up with:
> >
> > {"people":[{"person":{"age":"27",...}}, {"person":{"age":...}}]}
> >
> > right?
> >
> > I agree, people should be able to configure it.
>
> Yeah. For the current approach of not having element names for each
> array element, it can be misleading. As it stands now, you don't have
> "people". Instead, you have "person" which is corresponds with a list
> of "person" objects. It can be confusing.

Agreed, it is not apparent how xml and json relate in this case.
On the other hand, json expression is much more simpler this way,
while containing all the info needed, and this (simplicity)
is what we wanted to provide.
I will make sure an option is available for you to confgure
json to get the format you requesting.

>
> I appreciate all of the team's hard work. Jersey is an amazing piece of
> software. I hope to contribute more than "ideas" at some time in the
> near future.

Thanks!


~Jakub

>
> Take care,
>
> Jeremy