users@jersey.java.net

Efficient encoding of homogeneous arrays(tables)

From: Markus Kohler <markus.kohler_at_gmail.com>
Date: Wed, 1 Apr 2009 16:07:40 +0200

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