users@jersey.java.net

[Jersey] Give back JSON Arrays rather than Objects

From: Lukas Lentner <kontakt_at_lukaslentner.de>
Date: Wed, 16 Nov 2011 17:16:40 +0100

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