title: Binding the nested json to @RequestBody object using Jackson converter
body: <p>I have two classes</p>
  
  <pre><code>public class Parent {
      private String name;
      private int age;
      private ArrayList&lt;Child&gt; children = new ArrayList&lt;Child&gt;();
      //Setters and getter to follow..
  }
  
  public Class Child {
      private String name;
      private int age;
  }
  </code></pre>
  
  <p>Spring config includes:</p>
  
  <pre><code>&lt;bean id="jsonMessageConverter"
      class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" /&gt;
  
  &lt;bean
      class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;
      &lt;property name="messageConverters"&gt;
          &lt;list&gt;
              &lt;ref bean="jsonMessageConverter" /&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;  
  </code></pre>
  
  <p>Controller looks like the following:</p>
  
  <pre><code>@RequestMapping(value = "/parents", 
                  method = RequestMethod.POST, 
                  headers="Content-Type=application/json")
  public @ResponseBody Parent add(@RequestBody Parent parent, Model model) {
  
      logger.debug("Received request to add a parent");
      Parent tempParent = parentService.add(parent); // This will persist the parent object to the DB.. (Helper class)
      return tempContract;
  }
  </code></pre>
  
  <p>In a normal circumstances, it should bind the incoming json to Parent and return the Parent as a Json in the response. And it's giving me the exception: "The request sent by the client was syntactically incorrect." with the following input Json:</p>
  
  <pre><code>{
      "name" : "foo",
      "age" : "45",
      "children" : [ 
        {
           "name" : "bar",
           "age" : "15""
        },
        {
           "name" : "baz",
           "age" : "10""        
        }
      ]
  } 
  </code></pre>
  
  <p>So tried changing the json and it works just fine binding both @RequestBody and @ResponseBody with the following formats:</p>
  
  <pre><code>{
      "name" : "foo",
      "age" : "45",
      "children" : []
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>{
      "name" : "foo",
      "age" : "45",
      "children" : [ 
        {}
      ]
  } 
  </code></pre>
  
  <p>So I'm assuming there is something wrong biding the actual child class or with the way I'm passing the Json object wrt Child object. Could someone please help me out here. Also, is it suggested to use</p>
  
  <pre><code> private ArrayList&lt;HashMap&lt;String, Child&gt;&gt; children = new ArrayList&lt;HashMap&lt;String, Child&gt;&gt;();
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>private ArrayList&lt;Child&gt; children = new ArrayList&lt;Child&gt;();
  </code></pre>
  
  <p>Thank you.</p>