Skip to content

Commit 6597d7c

Browse files
committed
spring-projects#56 - Upgraded to spring HATEOAS 0.17 snapshots.
Simplified usage of ParameterizedTypeReference through newly introduced TypeReferences class. Moved to Java 8 streams for final output.
1 parent 797db3e commit 6597d7c

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

rest/starbucks/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
<version>1.0.0.BUILD-SNAPSHOT</version>
1313
</parent>
1414

15+
<properties>
16+
<spring-hateoas.version>0.17.0.BUILD-SNAPSHOT</spring-hateoas.version>
17+
</properties>
18+
1519
<dependencies>
1620

1721
<dependency>

rest/starbucks/src/main/java/example/stores/StarbucksClient.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,21 +18,20 @@
1818
import java.net.URI;
1919
import java.util.HashMap;
2020
import java.util.Map;
21+
import java.util.stream.StreamSupport;
2122

22-
import org.springframework.core.ParameterizedTypeReference;
2323
import org.springframework.hateoas.MediaTypes;
2424
import org.springframework.hateoas.PagedResources;
2525
import org.springframework.hateoas.PagedResources.PageMetadata;
2626
import org.springframework.hateoas.Resource;
2727
import org.springframework.hateoas.client.Traverson;
28+
import org.springframework.hateoas.mvc.TypeReferences.PagedResourcesType;
2829

2930
/**
3031
* @author Oliver Gierke
3132
*/
3233
public class StarbucksClient {
3334

34-
private static final ParameterizedTypeReference<PagedResources<Resource<Store>>> TYPE_REFERENCE = new ParameterizedTypeReference<PagedResources<Resource<Store>>>() {};
35-
3635
public static void main(String[] args) {
3736

3837
Traverson traverson = new Traverson(URI.create("http://localhost:8080"), MediaTypes.HAL_JSON);
@@ -44,19 +43,16 @@ public static void main(String[] args) {
4443
PagedResources<Resource<Store>> resources = traverson. //
4544
follow("stores", "search", "by-location").//
4645
withTemplateParameters(parameters).//
47-
toObject(TYPE_REFERENCE);
46+
toObject(new PagedResourcesType<Resource<Store>>() {});
4847

4948
PageMetadata metadata = resources.getMetadata();
5049

5150
System.out.println(String.format("Got %s of %s stores: ", resources.getContent().size(),
5251
metadata.getTotalElements()));
5352

54-
for (Resource<Store> resource : resources) {
55-
56-
Store store = resource.getContent();
57-
58-
System.out.println(String.format("- %s - %s", store.name, store.address));
59-
}
53+
StreamSupport.stream(resources.spliterator(), false).//
54+
map(Resource::getContent).//
55+
forEach(store -> String.format("- %s - %s", store.name, store.address));
6056
}
6157

6258
static class Store {

0 commit comments

Comments
 (0)