title: Spring and returning large volume of Json data
body: <p>My project is based on Java 8 and uses Spring throughout
  I have a service that returns a bean which contains a list of beans in it.</p>
  
  <p>Here is the code
  <strong>API Method</strong></p>
  
  <pre><code>@RequestMapping(value = "/search",", produces = { MediaType.APPLICATION_JSON_VALUE }, method = RequestMethod.POST)
  @ResponseBody
  public DeferredResult&lt;EmpAdvancedSearchPageBean&gt; getSearch(
          @RequestBody final EmpBean empBean) {
  
      LOGGER.info("Pre getSearch");
      EmpSearchPageBean searchPageBean = dataService.getSearch(empBean);
      LOGGER.info("Post getSearch");
  
      LOGGER.info("Pre set deffered result");
      DeferredResult&lt;EmpSearchPageBean&gt; deferredResult = new DeferredResult&lt;&gt;();
      deferredResult.setResult(searchPageBean);
      LOGGER.info("Post set deffered result");
  
      return deferredResult;
  }
  </code></pre>
  
  <p><strong>EmpSearchPageBean</strong> </p>
  
  <pre><code>public class EmpSearchPageBean implements java.io.Serializable   {
  
      private static final long serialVersionUID = 8085664391632415982L;
  
      @JsonProperty("draw")
      private Integer draw;
  
      @JsonProperty("recordsTotal")
      private Integer recordsTotal;
  
      @JsonProperty("recordsFiltered")
      private Integer recordsFiltered;
  
      @JsonProperty("data")
      private List&lt;EmpSearch&gt; data;   
  }   
  </code></pre>
  
  <p><strong>EmpSearch</strong></p>
  
  <pre><code>public class EmpSearch implements java.io.Serializable   {
  
      private static final long serialVersionUID = -7665557350420327753L;
  
      @JsonProperty("divisionDesc")
      private String divisionDesc;
  
      @JsonProperty("corpId")
      private String corpId;
  
      @JsonProperty("businessUnitDesc")
      private String businessUnitDesc;
  
      @JsonProperty("fdirName")
      private String fdirName;
  
  }
  </code></pre>
  
  <p>If the list of data ( List data;  ) contains 500 records - this service returns in about 2 seconds
  However if it contains around 2000 records (which is a common use case), it can take up to 2 minutes to return</p>
  
  <p>Based on my log statements - it takes about 2 seconds to return this data from the database and the rest of the time is taken up producing the json.</p>
  
  <p>I am using Spring Web version 4.3.3.RELEASE.
  from the debug logs I can see that it is using the class org.springframework.http.converter.json.MappingJackson2HttpMessageConverter</p>
  
  <p>Can anyone offer any advise on what I need to do in order to render large quantities of json data successfully?</p>