title: Configuring ObjectMapper in Spring
body: <p>my goal is to configure the <code>objectMapper</code> in the way that it only serialises element which are annotated with <code>@JsonProperty</code>.</p>
  
  <p>In order to do so I followed this <a href="http://wiki.fasterxml.com/JacksonFeatureAutoDetect" rel="noreferrer" title="explanation">explanation</a> which says how to configurate the objectmapper.</p>
  
  <p>I included the custom objectmapper as described <a href="https://stackoverflow.com/questions/3591291/spring-jackson-and-customization-e-g-customdeserializer">here</a>.</p>
  
  <p>However when the class <code>NumbersOfNewEvents</code> is serialized it still contains all attributes in the json.</p>
  
  <p>Does anybody have a hint?
  Thanks in advance</p>
  
  <p>Jackson 1.8.0
  spring 3.0.5</p>
  
  <p><strong>CustomObjectMapper</strong></p>
  
  <pre><code>public class CompanyObjectMapper extends ObjectMapper {
      public CompanyObjectMapper() {
          super();
          setVisibilityChecker(getSerializationConfig()
                  .getDefaultVisibilityChecker()
                  .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)
                  .withFieldVisibility(JsonAutoDetect.Visibility.NONE)
                  .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
                  .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
                  .withSetterVisibility(JsonAutoDetect.Visibility.DEFAULT));
      }
  }
  </code></pre>
  
  <p><strong>servlet.xml</strong></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"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"&gt;
  
      &lt;context:component-scan base-package="de.Company.backend.web" /&gt;
  
      &lt;mvc:annotation-driven /&gt;
  
      &lt;bean
          class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;
          &lt;property name="messageConverters"&gt;
              &lt;list&gt;
                  &lt;bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"&gt;
                      &lt;property name="objectMapper" ref="jacksonObjectMapper" /&gt;
                  &lt;/bean&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="jacksonObjectMapper" class="de.Company.backend.web.CompanyObjectMapper" /&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>NumbersOfNewEvents</strong></p>
  
  <pre><code>public class NumbersOfNewEvents implements StatusAttribute {
  
      public Integer newAccepts;
      public Integer openRequests;
  
      public NumbersOfNewEvents() {
          super();
      }
  }
  </code></pre>