Wednesday, January 28, 2015

Use generics with RestTemplate

To use generics with RestTemplate,

you can use ParameterizedTypeReference as follows:

ResponseEntity<PagedResources<Customer>> responseEntity = restTemplate.exchange(
url, HttpMethod.GET, null,
new ParameterizedTypeReference<PagedResources<Customer>>() {},
port, 0, 100);
PagedResources<Customer> resources = responseEntity.getBody();
List<Customer> customers = new ArrayList(resources.getContent());
System.out.println(customers);
System.out.println(customers.get(0).getClass());

exchange() method is only supported.

Reference:
http://www.java-allandsundry.com/2014/01/consuming-spring-hateoas-rest-service.html

No comments:

Post a Comment