title: Get back an Object List from a Spring controller to a AJAX request
body: <p>I want to return a List of object from a Spring controller to an AJAX request.</p>
  
  <p><strong>AJAX request:</strong></p>
  
  <pre><code>function doAjaxPost(date) {
      $.ajax({
          type : "POST",
          contentType : "application/json",
          url : "&lt;%="/water-consumer" + homepageURL + "/hourConsumption"%&gt;",
          data : date,
          dataType : 'json',
          success : function(response) {
              if(response != null)
                  showHourConsumption(response);
          }
      });
  }
  </code></pre>
  
  <p><strong>Spring controller:</strong></p>
  
  <pre><code>@RequestMapping(value = "/{username}/hourConsumption", method=RequestMethod.POST, produces="application/json")
  public @ResponseBody List&lt;HourConsumption&gt; getHoursConsumptions(@RequestBody String day, HttpSession session, Model model) {
      // do something ....
      Household household = (Household)session.getAttribute("household");
      List&lt;HourConsumption&gt; consumptions = this.mrs.getHoursConsumption(household.getSmart_meter().getOid(), day);
      // do something 
  
      if(consumptions == null) //check if what get back from something is not null
          return null;
      else
          return consumptions; 
  }
  </code></pre>
  
  <p>Now, the AJAX request goes right, so I receive the request from the controller and it generates the correct <em>consumptions (List)</em> but when it returns the List, the browser gives me back the following <strong>error</strong>:</p>
  
  <blockquote>
    <p>Failed to load resource: the server responded with a status of 406
    (Not Acceptable)</p>
  </blockquote>
  
  <p>Someone could tell me how can I do this things or the correct way to do so?
  Thank you very much!</p>