users@jersey.java.net

Re: [Jersey] Upgraded from Jersey 1.1 to 1.4, and JSON now has "null" values throughout

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Tue, 28 Sep 2010 16:57:07 -0700

On Tue, Sep 28, 2010 at 3:08 PM, Tim McCune <tim_at_mccune.name> wrote:
> When using Jersey 1.1, if I had an object with properties that were null,
> they simply didn't appear in the JSON output (same as XML).
>
> {"message":"foo"}
>
> I just upgraded to Jersey 1.4, and now my JSON output has a bunch of "null"
> values in the output:
>
> {"message":"foo","updated":null,"created":null}
>
> I guess this has to do with the fact that Jersey switched to using Jackson
> for its JSON rendering?  I found a mention here:
> http://docs.codehaus.org/display/JACKSON/FAQ
> that including these "null" properties is actually the default behavior in
> Jackson (??), and there is a way to turn it off, but I don't see any good
> way to get at the underlying objectMapper object through the JAX-RS APIs.
>
> Can anyone offer any suggestions?

You should be able to register provider for ObjectMapper, and then
construct, configure and serve that?

-+ Tatu +-