title: Parsing Json file using Spring RestTemplate
body: <p>I have a basic SpringBoot app. using Spring Initializer, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR.</p>
  
  <p>I connect to URL and print the response:</p>
  
  <pre><code>BufferedReader br = new BufferedReader(new InputStreamReader(
                  (conn.getInputStream())));
  
          StringBuilder response = new StringBuilder("");
          String output;
          while ((output = br.readLine()) != null) {
              response.append(output);
          }
  </code></pre>
  
  <p>with this result:</p>
  
  <pre><code>{"data":[{"device":"18AE63","time":1494516023,"data":"3235","snr":"36.72","linkQuality":"GOOD"},{"device":"18AE63","time":1494515750,"data":"484f4c41","snr":"35.69","linkQuality":"GOOD"}],"paging":{}}
  </code></pre>
  
  <p>But when I use RestTemplate</p>
  
  <pre><code>RestTemplate restTemplate = new RestTemplate();
  
           List&lt;HttpMessageConverter&lt;?&gt;&gt; messageConverters = new ArrayList&lt;HttpMessageConverter&lt;?&gt;&gt;();        
           MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
  
           converter.setSupportedMediaTypes(Arrays.asList(MediaType.ALL));         
           messageConverters.add(converter);  
           restTemplate.setMessageConverters(messageConverters);  
  
           MessageList messageList = 
                      restTemplate.getForObject(url, MessageList.class);
  </code></pre>
  
  <p>I got this error:</p>
  
  <pre><code>Exception in thread "main" org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON document: Unexpected character ('&lt;' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
   at [Source: java.io.PushbackInputStream@1d119efb; line: 1, column: 2]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('&lt;' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
   at [Source: java.io.PushbackInputStream@1d119efb; line: 1, column: 2]
      at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:234)
      at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:219)
      at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:95)
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:655)
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613)
      at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:287)
      at com.tdk.web.controllers.restful.client.RestTemplateGETExample.main(RestTemplateGETExample.java:49)
  Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('&lt;' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
   at [Source: java.io.PushbackInputStream@1d119efb; line: 1, column: 2]
      at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1702)
      at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:558)
      at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:456)
      at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2689)
      at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:878)
      at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:772)
      at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3834)
      at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3783)
      at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2922)
      at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:231)
      ... 6 more
  </code></pre>
  
  <p>the POJO:</p>
  
  <pre><code>@JsonInclude(JsonInclude.Include.NON_NULL)
  @JsonPropertyOrder({
  "data",
  "paging"
  })
  public class MessageList {
  
      @JsonProperty("data")
      private List&lt;Message&gt; data = null;
      @JsonProperty("paging")
      private Paging paging;
      @JsonIgnore
      private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
  
      @JsonProperty("data")
      public List&lt;Message&gt; getData() {
      return data;
      }
  
      @JsonProperty("data")
      public void setData(List&lt;Message&gt; data) {
      this.data = data;
      }
  
      @JsonProperty("paging")
      public Paging getPaging() {
      return paging;
      }
  
      @JsonProperty("paging")
      public void setPaging(Paging paging) {
      this.paging = paging;
      }
  
      @JsonAnyGetter
      public Map&lt;String, Object&gt; getAdditionalProperties() {
      return this.additionalProperties;
      }
  
      @JsonAnySetter
      public void setAdditionalProperty(String name, Object value) {
      this.additionalProperties.put(name, value);
      }
  
      @Override
      public String toString() {
          return "MessageList [data=" + data + ", paging=" + paging + ", additionalProperties=" + additionalProperties
                  + "]";
      }
  }
  </code></pre>