users@jersey.java.net

[Jersey] Re: Give back JSON Arrays rather than Objects

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Fri, 18 Nov 2011 15:07:57 +0100

Hi Lukas,

We currently do not provide such a functionality in Jersey.
It should not be hard to implement a new container response filter (see [1])
to take care of the Object->Array transformation.

Although i am not sure how you would consume such an array on the client
side.
One possibility would be to using an opposite, Array->Object,
transformation (see [2]),
another would be some sort of a low-level processing there.

HTH,

~Jakub


[1]http://jersey.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/spi/container/ContainerResponseFilter.html
[2]http://jersey.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/client/filter/ClientFilter.html



On 16.11.2011 17:16, Lukas Lentner wrote:
>
> Hi folks,
>
> Currently I'm trying to minimize the data sent over the net by my
> jersey application. I use the Jettinson JSON Marshaller and Iwould
> like to have rather Arrays containing the data than Objects - since I
> repeat all the time the fieldnames.
>
> In theory you can leave out all field names if you can rely on a
> special format (order of fields ...). What I mean is the difference of
> these two code examples:
>
> {
>
> name: "Hallo",
>
> tags: [
>
> {
>
> label: "Tag1"
>
> },
>
> {
>
> label: "Tag2"
>
> }
>
> ]
>
> }
>
> If I know that I get back ONE USER (which has a NAME and TAGS by spec)
> and that a TAG has only a LABEL. The following JSON should be enough
> to interpret the data:
>
> ["Hallo",[["Tag1"],["Tag2"]]]
>
> Is there an easy way to tell the marshaller or wohever to do so (maybe
> I have to order fields by name or with annotations or an XML-Spec)???
>
> Thankx
>
> Lukas
>