title: JSON plus spring mvc 3.2 error 415 (Unsupported Media Type)
body: <p>What did I do wrong? I try to use Spring mvc and JSON. When I try to debug my code I am looking that javascript works but doesn't works controller. In browser I get error  415 Unsupported Media Type.</p>
  
  <p>Script:</p>
  
  <pre><code>$(document).ready(function() {
    $('#newSmartphoneForm').submit(function(event) {
  
        var producer = $('#producer').val();
        var model = $('#model').val();
        var price = $('#price').val();
        var json = { "producer" : producer, "model" : model, "price": price};
  
      $.ajax({
          url: $("#newSmartphoneForm").attr( "action"),
          data: JSON.stringify(json),
          type: "POST",
  
          beforeSend: function(xhr) {
              xhr.setRequestHeader("Accept", "application/json");
              xhr.setRequestHeader("Content-Type", "application/json");
          },
          success: function(smartphone) {
              var respContent = "";
  
              respContent += "&lt;span class='success'&gt;Smartphone was    created: [";
              respContent += smartphone.producer + " : ";
              respContent += smartphone.model + " : " ;
              respContent += smartphone.price + "]&lt;/span&gt;";
  
              $("#sPhoneFromResponse").html(respContent);         
          }
      });
  
      event.preventDefault();
    });
  
  });  
  </code></pre>
  
  <p>Controllers:</p>
  
  <pre><code>   @RequestMapping(value="/create", method=RequestMethod.POST, 
          produces = MediaType.APPLICATION_JSON_VALUE,
              consumes = MediaType.APPLICATION_JSON_VALUE)
  @ResponseBody
  public Smartphone createSmartphone(@RequestBody Smartphone smartphone) {
      return smartphoneService.create(smartphone);
  }
  </code></pre>