users@jersey.java.net

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

From: Tim McCune <tim_at_mccune.name>
Date: Thu, 30 Sep 2010 14:12:10 -0700

Thanks. I didn't realize that Jackson had this built in. Their
documentation seems badly out-of-date. I haven't been able to get it to
work with this code:

mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);

but using the deprecated version seems to work:

mapper.configure(SerializationConfig.Feature.WRITE_NULL_PROPERTIES, false);

At any rate, I realize that's now a question for the Jackson users mailing
list. :) However, I'm still surprised that Jersey decided to change its
default behavior to match what seems to be the default behavior of Jackson,
to serialize null values. I would have expected Jersey to remain consistent
with previous releases.

On Tue, Sep 28, 2010 at 4:57 PM, Tatu Saloranta <tsaloranta_at_gmail.com>wrote:

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