title: Trying to generify method with ResponseEntity and RestTemplate
body: <p>I have the method below where I am trying to make it more generic so that the method can take any type I want:</p>
  <pre class="lang-java prettyprint-override"><code>public PersonResult getAllPersons (PersonMeta meta) {
      final String uri = addParams(getURI(), meta);
      final ResponseEntity&lt;PersonResult&gt; response = this.restTemplate.getForEntity(uri, PersonResult .class);
      if (HttpStatus.NOT_FOUND.equals(response.getStatusCode())) {
          throw new HttpClientErrorException(&quot;There are no persons available.&quot;);
      }
      return response.getBody();
  }
  </code></pre>
  <p>My try: but returns <code>NullPointerException at response position</code></p>
  <pre class="lang-java prettyprint-override"><code>public &lt;T, R&gt; R getAllPersons (T meta) {
      final String uri = addParams(getURI(), meta);
      final ResponseEntity&lt;R&gt; response = (ResponseEntity&lt;R&gt;) this.restTemplate.getForEntity(uri, Object.class);
      if (HttpStatus.NOT_FOUND.equals(response.getStatusCode())) {
          throw new HttpClientErrorException(&quot;There are no persons available.&quot;);
      }
      return response.getBody();
  }
  </code></pre>