title: How to unmarshall a JSON object to a Java Class?
body: <p>I have Spring REST application that can marshall an object to JSON when a GET request occurs. However what should I do for POST methods. I send a JSON object but it can't unmarshall it into a Java object. Here is a method of my controller:</p>
  
  <pre><code>@RequestMapping(value = "/user", method = RequestMethod.POST)
  public void createUser(HttpServletResponse response, @RequestBody User user) { 
     ...
      response.setStatus(HttpServletResponse.SC_OK);
  }
  </code></pre>
  
  <p>I send my JSON like that:</p>
  
  <pre><code>        var userName = $('#userName').val();
          var password = $('#password').val();
          var mail = $('#mail').val();
          var admin = $("#admin").is(':checked');
          var user = {userName: userName, password: password, mail: mail, admin:admin};
          $.ajax({
              async : false,
              type: 'POST',
              contentType: 'application/json',
              url: '/sfd/user',
              data: user,
              dataType: 'json',
              success: function(data) {
                 ...
              },
              error: function(data) {
                  ...
              }
          });
  </code></pre>
  
  <p><strong>PS:</strong>
  Here: <a href="http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/" rel="nofollow">http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/</a> it says: </p>
  
  <blockquote>
    <p>If there are validation errors, a HTTP 400 is returned with the
    error messages, otherwise a HTTP 200 is returned.</p>
  </blockquote>
  
  <p>I have 400 Bad Request Error. Maybe the problem is related to that?</p>
  
  <p><strong>PS2:</strong> Should I send User object after I set all its elements? I mean User object has some other attributes, i.e. address but I don't set and send it from client.</p>
  
  <p><strong>PS3:</strong> When I debug AbstractHandlerExceptionResolver's resolveException method I see that error. It says 'u' is undefined character(I tested it that 'u' is the first key of JSON => userName's first character).</p>