From 6597d7ca9585653ef32bfccfabd3827a1cf47ac7 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Mon, 2 Mar 2015 23:00:44 +0100 Subject: [PATCH] #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. --- rest/starbucks/pom.xml | 4 ++++ .../java/example/stores/StarbucksClient.java | 18 +++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rest/starbucks/pom.xml b/rest/starbucks/pom.xml index 0df9cf7c..6b5a06b6 100644 --- a/rest/starbucks/pom.xml +++ b/rest/starbucks/pom.xml @@ -12,6 +12,10 @@ 1.0.0.BUILD-SNAPSHOT + + 0.17.0.BUILD-SNAPSHOT + + diff --git a/rest/starbucks/src/main/java/example/stores/StarbucksClient.java b/rest/starbucks/src/main/java/example/stores/StarbucksClient.java index e98a6544..cc20c15a 100644 --- a/rest/starbucks/src/main/java/example/stores/StarbucksClient.java +++ b/rest/starbucks/src/main/java/example/stores/StarbucksClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,21 +18,20 @@ package example.stores; import java.net.URI; import java.util.HashMap; import java.util.Map; +import java.util.stream.StreamSupport; -import org.springframework.core.ParameterizedTypeReference; import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.PagedResources; import org.springframework.hateoas.PagedResources.PageMetadata; import org.springframework.hateoas.Resource; import org.springframework.hateoas.client.Traverson; +import org.springframework.hateoas.mvc.TypeReferences.PagedResourcesType; /** * @author Oliver Gierke */ public class StarbucksClient { - private static final ParameterizedTypeReference>> TYPE_REFERENCE = new ParameterizedTypeReference>>() {}; - public static void main(String[] args) { Traverson traverson = new Traverson(URI.create("http://localhost:8080"), MediaTypes.HAL_JSON); @@ -44,19 +43,16 @@ public class StarbucksClient { PagedResources> resources = traverson. // follow("stores", "search", "by-location").// withTemplateParameters(parameters).// - toObject(TYPE_REFERENCE); + toObject(new PagedResourcesType>() {}); PageMetadata metadata = resources.getMetadata(); System.out.println(String.format("Got %s of %s stores: ", resources.getContent().size(), metadata.getTotalElements())); - for (Resource resource : resources) { - - Store store = resource.getContent(); - - System.out.println(String.format("- %s - %s", store.name, store.address)); - } + StreamSupport.stream(resources.spliterator(), false).// + map(Resource::getContent).// + forEach(store -> String.format("- %s - %s", store.name, store.address)); } static class Store {