users@jersey.java.net

Re: [Jersey] Efficient encoding of homogeneous arrays(tables)

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 01 Apr 2009 16:23:21 +0200

Hi Markus,

For the specific case of TreeSet it is possible to support with JAXB
you just need to convert the TreeSet instance to a JAXB bean that
supports the table header and table rows mechanism you require. But i
suspect that is not the answer you want to hear :-) It might also be
possible to extend JAXB to be smarter about how it encoded basic
collection data types, but i am not an expert in this area.

I think for the general cases of collections/arrays/tables you would
need to utilize a specific JSON library to get want you want and
integrate that library with a message body writer.

Paul.

On Apr 1, 2009, at 4:07 PM, Markus Kohler wrote:

> Hi,
> I wonder whether it's possible in Jersey to efficiently encode
> homogeneous collections/arrays/tables.
>
> Using JSON such a "table" will encoded like this (Iused a TreeSet):
>
> "jobs":[{"name":"sample0.doc","status":"printing...","pages":"0"},
> {"name":"sample1.doc","status":"printing...","pages":"1 "},
> {"name":"sample10.doc","status":"printing...","pages":"10"},
> {"name":"sample11 .doc","status":"printing...","pages":"11"},
> {"name":"sample12.doc","status":"prin ting...","pages":"12"},
> {"name":"sample13.doc","status":"printing...","pages":"13 "},
> {"name":"sample14.doc","status":"printing...","pages":"14"},
> {"name":"sample15 .doc","status":"printing...","pages":"15"},
> {"name":"sample16.doc","status":"prin ting...","pages":"16"},
> {"name":"sample17.doc","status":"printing...","pages":"17 "},
> {"name":"sample18.doc","status":"printing...","pages":"18"},
> {"name":"sample19 .doc","status":"printing...","pages":"19"},
> {"name":"sample2.doc","status":"print ing...","pages":"2"},
> {"name":"sample20.doc","status":"printing...","pages":"20"} ,
> {"name":"sample21.doc","status":"printing...","pages":"21"},
> {"name":"sample22.d oc","status":"printing...","pages":"22"},
> {"name":"sample23.doc","status":"printi
>
>
>
> It's obviously unnecessary to repeat all those "name" and "status"
> Strings.
>
> Because I want to show this data in a simple table, it should also
> be possible to encode it like this:
>
> "jobs":["header":["name","status","pages"],
> ["sample0.doc","printing...","0"],
> ["sample1.doc","printing...","1"] ...
>
> Please forgive me if the syntax is not completely correct, I'm not a
> Javascript expert. I still think you get the idea.
>
> I can imagine that since Jersey also supports XML and uses JAXB that
> there would be limitations of would could be done.
> Actually it seems to me that with XML you can get only close to
> JSON encoding.
>
> Has anyone here already solved this kind of problem?
>
>
>
> Regards,
> Markus