users@jersey.java.net

Re: strange JSON serialization

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Mon, 07 Jan 2008 16:30:32 +0100

Hi Akos,

please see in line...

On Mon, Jan 07, 2008 at 03:50:29PM +0100, Ákos Maróy wrote:
> I'm looking at the JSON serialization support in Jersey, and I find it a
> bit strange. I have basically an object called Choice, with two fields,
> called date (String) and type (int).
>
> The object is serialized as follows in JSON:
>
> {"choice":{"date":{"$":"01\/03\/2008"},"type":{"$":"-1"}}}

For jaxb beans, badgerfish notation [1] is used, which is what you see.
If you want something simpler you need to use JSONObject/JSONArray
instead of jaxb bean.

I am working on improving json generated from jaxb, but it is not likely
the whole thing will be ready for 0.5 release.

Jersey currently uses jettison project for json support.
Given that jettison provides two options for produced json notation,
i can imagine we can quickly provide a switch to get the other (Mapped Convention)
notation (see [3]). Will it work for you?

~Jakub


[1]http://badgerfish.ning.com/
[2]http://jettison.codehaus.org/
[3]http://jettison.codehaus.org/User%27s+Guide

>
> and for XML
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <choice><date>01/03/2008</date><type>-1</type></choice>
>
>
> by the very same function, depending on what Accept: HTTP header it
> receives.
>
> I'm wondering why the data values are serialized this way:
>
> "date":{"$":"01\/03\/2008"}
>
> whereas it could be much simpler:
>
> "date":"01\/03\/2008"
>
> and it would be much easier to handle the JSON-generated JavaScript
> object hierarchy:
>
> choice.date["$"] vs. choice.date
>
>
> Akos
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

-- 
Jakub Podlesak
http://blogs.sun.com/japod