title: Minimize data to be serialized for Spring web services rendering JSON data
body: <p>I was using STRUTS as a MVC framework till now.
  <br/>
  One of the best features struts allowed was :
  <b>A comma-delimited list of regular expressions can be passed to the JSON Result to restrict which properties will be serialized. ONLY properties matching any of these regular expressions will be included in the serialized output.</b></p>
  
  <p>Eg:</p>
  
  <pre><code>&lt;action name="GetAllGroups" class="com.example.action.GroupAction"          method="getAllGroups"&gt;
              &lt;result type="json"&gt;
                  &lt;param name="includeProperties"&gt;
                      ^groups\[\d+\]\.id, ^groups\[\d+\]\.name, ^groups\[\d+\]\.parent\.id
                  &lt;/param&gt;
              &lt;/result&gt;
  &lt;/action&gt;
  </code></pre>
  
  <p>This will serialize only desired parameters of the groups list thus reducing the payload or redundant data (Eg: other attributes of group like create time, update time, members etc)</p>
  
  <p>Now we are using SPRING MVC as we are migrating to web services and rendering JSON the data type for all requests.
  With following configuration:</p>
  
  <pre><code>&lt;bean
          class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;
          &lt;property name="messageConverters"&gt;
              &lt;list&gt;
                  &lt;ref bean="jsonConverter" /&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>The controller API is as follows:</p>
  
  <pre><code>@RequestMapping(value = "/groups", method = RequestMethod.GET)
  public @ResponseBody
  List&lt;Group&gt; getGroups() throws Exception {
      log.info("Getting all the groups");
      return myService.getAllGroups();
  }
  </code></pre>
  
  <p>This is working fine, my only concern being the amount of data being serialized.
  All the attributes of the Group object are serialized by jackson.</p>
  
  <p>Using @JsonIgnore for unwanted attribute is like static binding. As it will ignore the attributes with @JsonIgnore for serialization for all requests where Groups are served to client. (Eg: To populate Groups in dropdown only their id and name will suffice, but to populate it completely on client as a profile, I need all data)</p>
  
  <p>So my preference is a configuration specific to STRUTS, which can be applied for each request.</p>