users@jersey.java.net

[Jersey] nil instead of null

From: nbaliga <nbaliga_at_cleartrial.com>
Date: Thu, 22 Sep 2011 12:45:33 -0700 (PDT)

I annotate my POJOs with JAXB annotations and I had a question about Jersey's
behavior when it comes to attributes marked with @XmlElement(nillable =
true).

When I use the POJO Mapping Feature, I get, what I think is the correct JSON
notation, i.e.

 "attribute":null


However, for various reasons, I am forced to go with the JAXB Context
Resolver approach i.e. have a class such that:

class JAXBContextResolver
      implements ContextResolver<JAXBContext>


And in the constructor of said class, I set my JAXBContext instance =

 new JSONJAXBContext( JSONConfiguration.natural().rootUnwrapping( false
).humanReadableFormatting( true ).build(), .... );


By doing so, my understanding is that I am asking Jersey to use Jackson and
I get some more control over what it produces. Incidentally, the
rootUnwrapping feature is the reason for this approach over POJO Mapping
Feature.

Using the above, causes null attributes to show up as:

 "attribute":{"nil":true}


How do I go about getting Jersey to go back to using null instead of nil? I
know the default Jackson behavior is to use null and not nil, both from my
experimentation with the POJO mapping feature, as well as simple POCs using
Jackson directly.

Any help will be greatly appreciated.


--
View this message in context: http://jersey.576304.n2.nabble.com/nil-instead-of-null-tp6821681p6821681.html
Sent from the Jersey mailing list archive at Nabble.com.