users@jersey.java.net

Re: [Jersey] How do I marshal nested lists as JSON? I get an array of nulls or an array of one-element dictionaries containing an array.

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Mon, 20 Jul 2009 12:06:31 -0700

On Mon, Jul 20, 2009 at 10:01 AM, Martin Probst<mail_at_martin-probst.com> wrote:
>>> I am sorry, but IMHO using the JAXB->JSON way, you will not
>>> be able to get what you want.
>>
>> This is what I had expected. That really is unfortunate.
>
> I ran into very similar problems with JAXB, JSON and XML. I wonder
> what a potential solution would look like. The more I think about it,
> the more I think one would need something between a configuration file
> and a template mechanism to handle JSON and XML generation in a nice
> way. Which of course leaves the deserialization problem entirely
> uncovered.
>
> I actually wrote a trivial - about than 150 SLOC - reflection-based
> serializer for Java->JSON as the other possibilities were not what I
> wanted, but that also makes some assumptions that might not be
...

Just curious here -- what is/was missing from Jackson data binding? I
assume you checked it out.

Personally I think that trying to make XML and JSON serialization
parts interact (beyond simple things like possibly supporting same
bean annotations) is largely waste of time -- both can be solved
rather easily separately, as long as canonical data is viewed to be
objects. And thereby representations should always derive from the
primary canonical source; not from secondary rendition.

I mean, converting json to xml or vice versa is just asking for lots
of extra trouble, due to impedance (different data models). Clients
choose one or the other presentations to use: they don't care if there
is any relation between xml and json representations; just use one.
Server can use optimal mappings for each separately.

-+ Tatu +-