ObjectMapper using TypeReference not working when passed type in generic method
问题 This is the method: protected <T> TestPageResult<T> getTestPageResutForRequest(MockHttpServletRequestBuilder request) throws Exception { String responseJson = mockMvc.perform(request).andReturn().getResponse() .getContentAsString(); TestPageResult<T> response = getObjectMapper().readValue(responseJson, new TypeReference<TestPageResult<T>>() { }); return response; } I call it like this: TestPageResult<SomeDto> pageResult = this.<SomeDto>getTestPageResutForRequest(getRequest()); TestPageResult