title: Deserializing Nested objects using RestTemplate
body: <p>I am using RestTemplate and having issues deserializing an object. Here is what I am doing. The JSON response looks like,</p>
  <pre class="lang-java prettyprint-override"><code>{
      &quot;response&quot;: {
          &quot;Time&quot;: &quot;Wed 2013.01.23 at 03:35:25 PM UTC&quot;,
          &quot;Total_Input_Records&quot;: 5,
      },-
      &quot;message&quot;: &quot;Succeeded&quot;,
      &quot;code&quot;: &quot;200&quot;
  }
  </code></pre>
  <p>Converted this Json payload into a POJO using <a href="http://code.google.com/p/jsonschema2pojo" rel="nofollow noreferrer">jsonschema2pojo</a></p>
  <pre><code>public class MyClass {
      @JsonProperty(&quot;response&quot;)
      private Response response;
      @JsonProperty(&quot;message&quot;)
      private Object message;
      @JsonProperty(&quot;code&quot;)
      private Object code;
      private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
      //bunch of getters and setters here
  }
  public class Response {
      @JsonProperty(&quot;Time&quot;)
      private Date Time;
      @JsonProperty(&quot;Total_Input_Records&quot;)
      private Object Total_Input_Records;
      private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
  //bunch of getters and setters here
  }
  </code></pre>
  <p>Here is the request processing where I am getting the exception,</p>
  <pre><code>String url = &quot;http://example.com/someparams&quot;;
  RestTemplate template = new RestTemplate(
                  new HttpComponentsClientHttpRequestFactory());
  FormHttpMessageConverter converter = new FormHttpMessageConverter();
  List&lt;MediaType&gt; mediaTypes = new ArrayList&lt;MediaType&gt;();
  mediaTypes.add(new MediaType(&quot;application&quot;, &quot;x-www-form-urlencoded&quot;));
  converter.setSupportedMediaTypes(mediaTypes);
  template.getMessageConverters().add(converter);
  MyClass upload = template.postForObject(url, null, MyClass.class);
  </code></pre>
  <p>Here is the frustrating part, exception (deliberately trimmed, not full). Anything I am missing?</p>
  <pre><code>org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Unrecognized field &quot;Time&quot; (Class com.temp.pointtests.Response), not marked as ignorable
   at [Source: org.apache.http.conn.EofSensorInputStream@340ae1cf; line: 1, column: 22  (through reference chain: com.temp.pointtests.MyClass[&quot;response&quot;]-&gt;com.temp.pointtests.Response[&quot;Time&quot;]);] 
  </code></pre>
  <p><strong>+++++Update Solved++++++</strong></p>
  <p>I saw Spring added MappingJackson2HttpMessageConverter which uses Jackson 2. Because MappingJacksonHttpMessageConverter in my code above uses Jackson Pre2.0 versions and it doesn't work. It works for Jackson 2.0 however.  With MappingJackson2HttpMessageConverter available now, I can now add it to my RestTemplate and everything works fine :-). Here is the code for people who have the same issue,</p>
  <pre><code>String url = &quot;http://example.com/someparams&quot;;
  RestTemplate template = new RestTemplate();
  HttpHeaders headers = new HttpHeaders();
  headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);  
  HttpEntity request = new HttpEntity(headers);
  List&lt;HttpMessageConverter&lt;?&gt;&gt; messageConverters = new ArrayList&lt;HttpMessageConverter&lt;?&gt;&gt;();
  MappingJackson2HttpMessageConverter map = new MappingJackson2HttpMessageConverter();
  messageConverters.add(map);
  messageConverters.add(new FormHttpMessageConverter());
  template.setMessageConverters(messageConverters);
  MyClass msg = template.postForObject(url, request, MyClass.class);
  </code></pre>