title: Nested JSON to POJO
body: <p>I am trying to call an external RESTful web service and am in need of parsing out response that comes with a nested JSON. I am trying to parse out the following:</p>
  
  <blockquote>
    <p>{ "list": [ { "list_id" : "abcdef", "list_name" : "testing123" }, {"list_id" : "xyz", "list_name" : "testing456" }]}</p>
  </blockquote>
  
  <p>My POJO Class looks like this: </p>
  
  <pre><code>@JsonIgnoreProperties(ignoreUnknown = true)
  public class ListGetResponse {
      private String list = "";
      private SMSList lists;
  
      public String getList() {
          return list;
      }
  
      public void setList(String list) {
          this.list = list;
      }
  
      public SMSList getLists() {
          return lists;
      }
  
      public void setLists(SMSList lists) {
          this.lists = lists;
      }
  
      @Override
      public String toString() {
          return "SMSListGetResponse [list=" + list + "]";
      }
  
  
      @JsonIgnoreProperties(ignoreUnknown = true)
      public class SMSList {
          private String list = "";
          private String list_id = "";
          private String list_name = "";
  
  
          public String getList() {
              return list;
          }
          public void setList(String list) {
              this.list = list;
          }
          public String getList_id() {
              return list_id;
          }
          public void setList_id(String list_id) {
              this.list_id = list_id;
          }
          public String getList_name() {
              return list_name;
          }
          public void setList_name(String list_name) {
              this.list_name = list_name;
          }
          @Override
          public String toString() {
              return "SMSList [list_id=" + list_id + ", list_name=" + list_name
                      + "]";
          }
  
  
      }
  </code></pre>
  
  <p>I am calling this function through this method.</p>
  
  <pre><code>public void get()
  {
      RestTemplate restTemplate = SMSRestFactory.getRestTemplate();
  
      ResponseEntity&lt;ListGetResponse&gt; responseEntity = restTemplate.getForEntity(SMS_LIST_GET, ListGetResponse.class);
      ListGetResponse body = responseEntity.getBody();
      System.out.println(responseEntity.getBody());
      System.out.println(body);
  }
  </code></pre>
  
  <p>When calling get(); I receive the following StackTrace</p>
  
  <pre><code>  Exception in thread "main" org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of java.lang.String out of START_ARRAY token
   at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@165ae07; line: 1, column: 2] (through reference chain: com.em.ustms.sms.list.model.ListGetResponse["list"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_ARRAY token
   at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@165ae07; line: 1, column: 2] (through reference chain: com.em.ustms.sms.list.model.ListGetResponse["list"])
      at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readJavaType(MappingJackson2HttpMessageConverter.java:228)
      at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.read(MappingJackson2HttpMessageConverter.java:220)
      at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:95)
      at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:788)
      at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:773)
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:553)
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:506)
      at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:268)
      at com.em.ustms.sms.service.SMSListService.get(SMSListService.java:59)
      at com.em.ustms.sms.Application.main(Application.java:12)
  Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_ARRAY token
   at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@165ae07; line: 1, column: 2] (through reference chain: com.em.ustms.sms.list.model.ListGetResponse["list"])
      at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
      at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:691)
      at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:46)
      at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:11)
      at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:525)
      at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:99)
      at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:242)
      at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:118)
      at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2993)
      at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2158)
      at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readJavaType(MappingJackson2HttpMessageConverter.java:225)
      ... 9 more
  </code></pre>