Created
February 17, 2016 04:43
-
-
Save tmoreira2020/37a7ce6b966f00961680 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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