users@jersey.java.net

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

From: Markus Kohler <markus.kohler_at_gmail.com>
Date: Wed, 1 Apr 2009 17:52:46 +0200

Hi Paul,Thanks for you answer!

Yes I thought about the solution to convert it to another bean, and yes I
don't like the idea ;)

Ideally I would think that one would just annotate a generic Collection to
be homogeneous and then Jersey/JAXB would do the rest for me :)
The annotation would be needed because you cannot know (in general) whether
there would be subtypes stored in the Collection.


Do you have a reference about this "message body writer" you mentioned? I
would be interested to learn who this would work.

Regards,
Markus

On Wed, Apr 1, 2009 at 4:23 PM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:

> 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
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>