0

I have a spring webservice that returns a json response using spring.

The format the json is returned in is:

{"data": {
"bidPrice": 26.8,
"fundNames": null,
"offerPrice": 27.4,
"fundId": "123456789",
"fundDescription": "High Risk Equity Fund",
"lastUpdated": "2015-08-25T15:48:57"
}}

I want to remove any null objects(fundNames) from the returned response so it looks like

 {"data": {
  "bidPrice": 26.8,
  "offerPrice": 27.4,
   "fundId": "123456789",
   "fundDescription": "High Risk Equity Fund",
   "lastUpdated": "2015-08-25T15:48:57"
 }}

My beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<mvc:annotation-driven/>
<context:component-scan base-package="com.blog" />

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
    <property name="contentType" value="application/json"/>
</bean>

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
         <util:list id="beanList">
            <ref bean="jsonMessageConverter"/>
        </util:list>
        </property>
</bean>
<bean id="jsonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>

I'm using xsd to generate the java class so cannot use @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) in my POJO java class, please advise on how to set NON_NULL in spring.xml with the above config

Any help will be appreciated

Thanks

haja
  • 135
  • 1
  • 4
  • 12
  • 1
    possible duplicate of [Spring REST Service: how to configure to remove null objects in json response](http://stackoverflow.com/questions/12707165/spring-rest-service-how-to-configure-to-remove-null-objects-in-json-response) – Flowryn Aug 25 '15 at 08:18
  • duplicate of http://stackoverflow.com/questions/12707165/spring-rest-service-how-to-configure-to-remove-null-objects-in-json-response – MS Ibrahim Aug 25 '15 at 08:59

0 Answers0