title: ObjectMapper using TypeReference not working when passed type in generic method
body: <p>This is the method:</p>
  
  <pre><code>protected &lt;T&gt; TestPageResult&lt;T&gt; getTestPageResutForRequest(MockHttpServletRequestBuilder request) throws Exception {
      String responseJson = mockMvc.perform(request).andReturn().getResponse()
              .getContentAsString();
  
      TestPageResult&lt;T&gt; response = getObjectMapper().readValue(responseJson,
              new TypeReference&lt;TestPageResult&lt;T&gt;&gt;() {
              });
  
      return response;
  }
  </code></pre>
  
  <p>I call it like this:</p>
  
  <pre><code> TestPageResult&lt;SomeDto&gt; pageResult = this.&lt;SomeDto&gt;getTestPageResutForRequest(getRequest());
  </code></pre>
  
  <p>TestPageResult is:</p>
  
  <pre><code>protected static class TestPageResult&lt;T&gt; {
      private List&lt;T&gt; items;
      private long totalCount = -1;
  
      public TestPageResult() {
  
      }
      //omitted getters and setters
  
  }
  </code></pre>
  
  <p>The resulting pageResult.getItems() contains a List of LinkedHashMap instead of a list of SomeDto. If I were to just hardcode the SomeDto type in the objectMapper.readValue method I'd get the correct results.</p>
  
  <p>What's the problem?</p>
  
  <p>edit: The suggested duplicated did solve my problem - kind of.
  I used:</p>
  
  <pre><code>JavaType type = getObjectMapper().getTypeFactory().constructParametricType(TestPageResult.class, clazz);
  TestPageResult&lt;T&gt; response = getObjectMapper().readValue(responseJson, type);
  </code></pre>
  
  <p>Problem is there is no going around not passing down a Class argument to the method. So the method looks ugly due to both passing a generic type and the same thing as a Class. Obviously you can just not pass the generic now but this way a casting would be required and adding SuppressWarnings and so on.</p>