Description
Simon Wong opened SPR-7002 and commented
When I used RestTemplate to retrieve the result in Generic Type Container, the MappingJacksonHttpMessageConverter could not properly determine the type (due to erasure)
e.g.
List<MyDomain> myDomainList = restTemplate.getForObject(uri, List.class);
will throw ClassCastException
the MappingJacksonHttpMessageConverter could not determine that the List container should stores MyDomain objects by passing the List.class, it could only stores as List<LinkedHashedMap>
Recommend to add something similar to TypeReference in Jackson. http://wiki.fasterxml.com/JacksonInFiveMinutes (Section: Data Binding with Generics) to solve this issue.
Personal speaking, if the new HttpEntity could provide a setTypeReference() would be much convenient.
e.g.
HttpEntity httpEntity = new HttpEntity();
httpEntity.setTypeReference(new TypeReference<List<MyDomain>>() {});
List<MyDomain> myDomainList = restTemplate.getForObject(uri, httpEntity);
Affects: 3.0 GA, 3.0.1
Issue Links:
- Proper handling of parameterized types in RestTemplate [SPR-7023] #11685 Proper handling of parameterized types in RestTemplate
Referenced from: commits a1f6eab, 247c46e, 212daa1
0 votes, 7 watchers