title: Getting HTTP response as a java object
body: <p>I am using Spring Web to create a rest resource. I have created Document objects in Java similar to the Json response. When I use String.class as the response type, I get the response from the request. When I change the response to the class I have created the boy is null. </p>
  
  <p>Here is my HttpGettter</p>
  
  <pre><code>   private &lt;T&gt; T perform(String token, String resourcePath, Class&lt;T&gt; responseType, HttpMethod method, MultiValueMap&lt;String, String&gt; queryParams) {
       UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.newInstance()
            .scheme(protocol)
            .host(host);
  
      UriComponents uriComponents = uriComponentsBuilder.build();
      String url = uriComponents.toString();
  
      HttpHeaders headers = new HttpHeaders();
      headers.add("contentType","application/json");
  
      HttpEntity&lt;String&gt; requestEntity = new HttpEntity&lt;&gt;(headers);
      ResponseEntity&lt;T&gt; responseEntity = restTemplate.exchange(url, method, requestEntity, responseType);
      return responseEntity.getBody();
     }
       return null;
   }
  </code></pre>
  
  <p><strong>Json Document</strong></p>
  
  <pre><code>@JsonIgnoreProperties(ignoreUnknown = false)
  public class SiteDocument {
  
    @JsonProperty("id")
    private int siteID;
    @JsonProperty("site_name")
    private String siteName;
    @JsonProperty("url")
    private String url;
  }
  </code></pre>
  
  <p>Function call</p>
  
  <pre><code> perform(null, "/sites", SiteDocument[].class, HTTP.get,null)
  </code></pre>
  
  <p><strong>JSON Response</strong></p>
  
  <pre><code>{  
   "items":[  
    {  
       "id":5841970702,
       "site_name":"test",
       "url":"http://sample/again/",
       "pages":2,
       "policies":0,
       "product":[  
          "quality_assurance",
          "accessibility",
          "seo",
          "policy"
       ],
       "_links":{  
          "site":{  
             "href":"https://api.siteimprove.com/v2/sites/5841970702"
          }
       }
    },
  
    {  
       "id":5881398958,
       "site_name":"preview.site",
       "url":"http://sample.site",
       "pages":0,
       "policies":0,
       "product":[  
          "quality_assurance",
          "policy"
       ],
       "_links":{  
          "site":{  
             "href":"https://api.siteimprove.com/v2/sites/5881398958"
          }
       }
    }
   ],
   "total_items":5,
   "total_pages":1,
    "links":{  
    "self":{  
       "href":"https://api.siteimprove.com/v2/sites"
    }
    }
    }
  </code></pre>
  
  <p>Ignore the incorrect formatting of the JSON response. Edited to make it short.</p>
  
  <p><strong>Exception</strong></p>
  
  <blockquote>
    <p>Exception in thread "main"
    org.springframework.web.client.RestClientException: Could not extract
    response: no suitable HttpMessageConverter found for response type
    [class
    [Lcom.blueprint.siteimprove.webresources.documents.SiteDocument;]
    and content type [text/html]</p>
  </blockquote>
  
  <p><strong>Updated exception</strong></p>
  
  <blockquote>
    <p>Could not extract response: no suitable HttpMessageConverter found for
    response type [class
    [Lcom.coremedia.blueprint.siteimprove.webresources.documents.SiteDocument;]
    and content type [application/json;charset=utf-8]</p>
  </blockquote>
  
  <p>Added on headers the foollowing</p>
  
  <pre><code>  headers.add("Accept","application/json");
    headers.add("Content-Type","application/json");
  </code></pre>