dev@jersey.java.net

Jersey's default JSON notation

From: Mike Meessen <netmikey.ml_at_gmail.com>
Date: Mon, 22 Nov 2010 18:01:11 +0100

Hi there,

First of all, allow me to join the chorus: JAX-RS and Jersey are really
great and fun to use! This is what web services should have been from the
beginning ;-) Also, greetings to Paul Sandoz. It was a pleasure attending
your talk at Devoxx in Antwerp last week :-)

I fiddled around a bit with JAXB backed Jersey JSON output this weekend.
This was also my very first time checking out JAX-RS. I tried to stay as
close to JAX-RS (keeping everything non-Jersey-specific) as
possible. Everything was really smooth and straight forward. There has only
been one pitfall that took me quite some time to figure out: The JSON
notation configuration.

By default, Jersey uses what's called the MAPPED notation. I read somewhere
that this implementation was just the most straight forward one. But oddly
enough, it doesn't produce valid JSON (with regard to the Java Types behind
it). More precisely, numeric values are output with double quotes, which
makes them strings in JSON. Same thing for boolean values. There are also a
couple of issues with Lists not being represented as they should. I had to
switch to the NATURAL notation in the JSONConfiguration as explained in [1],
which, in turn, is not straight forward at all anymore.

I don't see why anybody would want to use the MAPPED notation, or am I
missing something? From what I understood, JETTISON_MAPPED and BADGERFISH
are also very special use cases so my guess is that > 90% of users would
want the NATURAL notation, which is why you really should make it the
default one.

Best regards,
Mike

[1] http://jersey.java.net/documentation/1.3/user-guide.html#d4e815