title: How to map JSON object to Spring Object
body: <p>How to map JSON object to Spring Object... I have AJAX, posting a JSON object to my Spring Controller but how do I make Spring turn that JSON into a Object in java</p>
  
  <p>Java Code:</p>
  
  <pre><code>@RequestMapping(method=RequestMethod.POST, value="/employee")
      public ModelAndView addEmployee(@RequestBody String body) {
  
          System.out.println("in post: " + body);
          Source source = new StreamSource(new StringReader(body));
  
  
          System.out.println("source: " + source.toString());
          //
          // how do I turn the JSON String into a Java Object?
          //
          return new ModelAndView(XML_VIEW_NAME, "object", body);
      }
  </code></pre>
  
  <p>JavaSript/html code:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  &lt;title&gt;This is a project to show how to use RESTful&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;script type="text/javascript"&gt;var contexPath = "&lt;%=request.getContextPath()%&gt;";&lt;/script&gt;
  &lt;script src="&lt;%=request.getContextPath()%&gt;/js/jquery.js"&gt;&lt;/script&gt;
  
  
  &lt;script type="text/javascript"&gt;
  function doAjaxPost() {  
  
  
      var queryString = $('#htmlform').serialize();
  
      alert("doAjaxPost Called :" + queryString +":");
  
         $.ajax({
              contentType : "application/json",
              dataType : 'json',
              type : "POST",
              url : contexPath + "/service/employee",
              data : queryString, //json serialization (like array.serializeArray() etc)
  
              success : function(data) {
                  alert("Thanks for submitting.  \n\n" + response.result);
                 // response
              },
              error : function(request, status, error) {
                     alert('Error: ' + e); 
              }
          });
      }  
  &lt;/script&gt;
  
  &lt;H1&gt;Add Employee&lt;/H1&gt;
  
  &lt;p&gt;
  &lt;form name="htmlform" id="htmlform"&gt;
  &lt;table border=1&gt;
      &lt;thead&gt;&lt;tr&gt;
          &lt;th&gt;ID&lt;/th&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;Email&lt;/th&gt;
      &lt;/tr&gt;&lt;/thead&gt;
  
      &lt;tr&gt;
          &lt;td&gt;&lt;input  type="text" name="ID" maxlength="5" size="3"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input  type="text" name="Name" maxlength="10" size="10"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input  type="text" name="Email" maxlength="10" size="10"&gt;&lt;/td&gt;
      &lt;/tr&gt;
  
  &lt;/table&gt;
  &lt;input type="button" value="Save Employee" onclick="doAjaxPost();" /&gt;
  &lt;p&gt;
  &lt;p&gt;
  &lt;/form&gt;
  [&lt;a href="http://localhost:8080/RESTful/service/employees"&gt;List all Employees&lt;/a&gt; | &lt;a href="add.jsp"&gt;Employee Form Test&lt;/a&gt;]
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>