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:33:57 +0100

Viraj,

One more thing: to ignore the null values, you will probably also
need to provide your own Jackson ObjectMapper provider
with the Jackson SerializationConfig.Feature WRITE_NULL_PROPERTIES [3]
set to false. Please see [2] for details on how to hook your custom
ObjectMapper into Jersey.

HTH,

~Jakub

[2]http://download.java.net/maven/2/com/sun/jersey/samples/jacksonjsonprovider/1.6-ea06/jacksonjsonprovider-1.6-ea06-project.zip
[3]http://jackson.codehaus.org/1.7.0/javadoc/org/codehaus/jackson/map/SerializationConfig.Feature.html#WRITE_NULL_PROPERTIES

On 03/24/2011 10:18 PM, Jakub Podlesak wrote:
> 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.
>>
>
>