title: how to configure spring mvc 3 to not return "null" object in json response?
body: <p>a sample of json response looks like this:</p>
  
  <pre><code>{"publicId":"123","status":null,"partner":null,"description":null}
  </code></pre>
  
  <p>It would be nice to truncate out all null objects in the response. In this case, the response would become <code>{"publicId":"123"}</code>. </p>
  
  <p>Any advice? Thanks!</p>
  
  <p>P.S: I think I can do that in Jersey. Also I believe they both use Jackson as the JSON processer. </p>
  
  <p>Added Later:
  My configuration:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
      &lt;!-- Scans the classpath of this application for @Components to deploy as beans --&gt;
      &lt;context:component-scan base-package="com.SomeCompany.web" /&gt;
  
      &lt;!-- Application Message Bundle --&gt;
      &lt;bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
          &lt;property name="basename" value="/WEB-INF/messages/messages" /&gt;
          &lt;property name="cacheSeconds" value="0" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- Configures Spring MVC --&gt;
      &lt;import resource="mvc-config.xml" /&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"&gt;
  
      &lt;!-- Configures the @Controller programming model --&gt;
      &lt;mvc:annotation-driven /&gt;
  
      &lt;!-- Forwards requests to the "/" resource to the "welcome" view --&gt;
      &lt;!--&lt;mvc:view-controller path="/" view-name="welcome"/&gt;--&gt;
  
      &lt;!-- Configures Handler Interceptors --&gt;    
      &lt;mvc:interceptors&gt;
          &lt;!-- Changes the locale when a 'locale' request parameter is sent; e.g. /?locale=de --&gt;
          &lt;bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" /&gt;
      &lt;/mvc:interceptors&gt;
  
      &lt;!-- Saves a locale change using a cookie --&gt;
      &lt;bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" /&gt;
  
      &lt;!--&lt;bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"&gt;
          &lt;property name="mediaTypes"&gt;
              &lt;map&gt;
                  &lt;entry key="atom" value="application/atom+xml"/&gt;
                  &lt;entry key="html" value="text/html"/&gt;
                  &lt;entry key="json" value="application/json"/&gt;
                  &lt;entry key="xml" value="text/xml"/&gt;
              &lt;/map&gt;
          &lt;/property&gt;
          &lt;property name="viewResolvers"&gt;
              &lt;list&gt;
                  &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
                      &lt;property name="prefix" value="/WEB-INF/views/"/&gt;
                      &lt;property name="suffix" value=".jsp"/&gt;
                  &lt;/bean&gt;
              &lt;/list&gt;
          &lt;/property&gt;
          &lt;property name="defaultViews"&gt;
              &lt;list&gt;
                  &lt;bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" /&gt;
                  &lt;bean class="org.springframework.web.servlet.view.xml.MarshallingView" &gt;
                      &lt;property name="marshaller"&gt;
                          &lt;bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller" /&gt;
                      &lt;/property&gt;
                  &lt;/bean&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  --&gt;
    &lt;!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory --&gt;
      &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix" value="/WEB-INF/views/"/&gt;
          &lt;property name="suffix" value=".jsp"/&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>My code:  </p>
  
  <pre><code>@Controller
  public class SomeController {
      @RequestMapping(value = "/xyz", method = {RequestMethod.GET, RequestMethod.HEAD},
      headers = {"x-requested-with=XMLHttpRequest","Accept=application/json"}, params = "!closed")
      public @ResponseBody
      List&lt;AbcTO&gt; getStuff(
            .......
      }
  }
  </code></pre>