users@jersey.java.net

[Jersey] Re: Ignoring null elements in JSON

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Thu, 24 Mar 2011 22:18:13 +0100

Hello Viraj,

please try to use the POJO mapping feature [1] rather than
the JAXB->JSON approach. That should cover your use case.

Server side config:

<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>

Client side config:

ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING,
Boolean.TRUE);
Client client = Client.create(clientConfig);

HTH,

~Jakub

[1][1]http://jersey.java.net/nonav/documentation/1.6-SNAPSHOT/json.html#d4e894


On 03/23/2011 07:48 PM, viraj wrote:
> Hi,
>
> I am using the JAXBContextResolver for configuring JSON with mapped builder.
> We have the requirement in our project in which i have to ignore the
> elements which has null values in it. I tried using other notations like
> natural and mapped Jettison. But with Jettison the null value gets converted
> into an emtpy string.For eg I am getting-
> {"Person":{"givenName":"xxxx","familyName":"yyyy","middleName":null}}
>
> But as middleName is null I want to ignore it and I want like this -
>
> {"Person":{"givenName":"xxxx","familyName":"yyyy"}}
>
> Can anybody please help me how we can achieve this in JAXBCOntextResolver.
>
> Thanks
> Viraj
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Ignoring-null-elements-in-JSON-tp6201480p6201480.html
> Sent from the Jersey mailing list archive at Nabble.com.
>