Skip to content

Instantly share code, notes, and snippets.

@tmoreira2020
Created February 17, 2016 04:43
Show Gist options
  • Save tmoreira2020/37a7ce6b966f00961680 to your computer and use it in GitHub Desktop.
Save tmoreira2020/37a7ce6b966f00961680 to your computer and use it in GitHub Desktop.
@Test
public void test() {
RestTemplate restTemplate = restTemplate();
Link next = new Link("http://localhost:8080/v1/city?size=250&sort=name&name.dir=asc");
do {
System.out.println(next.getHref());
ResponseEntity<PagedResources<City>> responseEntity = restTemplate.exchange(next.getHref(), HttpMethod.GET, null,
new ParameterizedTypeReference<PagedResources<City>>() {
});
PagedResources<City> resources = responseEntity.getBody();
for (City city : resources) {
System.out.println(city.getName());
}
next = resources.getNextLink();
} while (next != null);
}
private RestTemplate restTemplate() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new Jackson2HalModule());
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
converter.setObjectMapper(mapper);
return new RestTemplate(Collections.<HttpMessageConverter<?>> singletonList(converter));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment