I'm using apache-cxf 2.7.11
+ jackson (codehaus) 1.9.13
+ spring 3.5
in my REST services web-container. I was wondering what would be the best way to remove null
value fields from REST responses.
For example:
My response is now like this:
{
"name": "MyName",
"age": 10,
"address": null
}
I want my response to be like this (the address
field has been removed):
{
"name": "MyName",
"age": 10
}
I've read about apache-cxf
interceptors and filters here:
- http://cxf.apache.org/docs/jax-rs-filters.html
- http://cxf.apache.org/docs/jax-rs-data-bindings.html
and wondering what is the best practice? is there any configurable setting that I can change instead of implementing my own filer or interceptor class?
I'm using beans.xml
file for configuration, thus I'm looking on how to config it all here, where my beans are:
<bean id="jaxrsRestJacksonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper"/>
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider">
<property name="mapper" ref="jaxrsRestJacksonObjectMapper"/>
</bean>
<jaxrs:server id="restContainer" address="/">
<jaxrs:serviceBeans>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
</jaxrs:providers>
</jaxrs:server>
Cheers!