diff --git a/src/main/asciidoc/index.adoc b/src/main/asciidoc/index.adoc index 5a73e433..1930df8a 100644 --- a/src/main/asciidoc/index.adoc +++ b/src/main/asciidoc/index.adoc @@ -381,17 +381,37 @@ There are more options to customize template parameters at each level. include::{baseDir}/src/test/java/org/springframework/hateoas/client/TraversonTests.java[tag=hop-with-param] ---- -The `.withParam(key, value)` make it simple to add URI Template variables. +The static `rel(...)` function is a convenient way to create define a single `Hop`. Using `.withParameter(key, value)` makes it simple to specify URI Template variables. + +NOTE: `.withParameter()` returns a new Hop object that is chainable. You can string together as many `.withParameter` as you like. The result is a single Hop definition. [source,java,indent=0] ---- include::{baseDir}/src/test/java/org/springframework/hateoas/client/TraversonTests.java[tag=hop-put] ---- -It's also possible to load an entire `Map` of parameters via `.withParams(Map)`. +It's also possible to load an entire `Map` of parameters via `.withParameters(Map)`. NOTE: `follow()` is chainable, meaning you can string together multiple hops as shown above. You can either put multiple, simple string-based rels (`follow("items", "item")`) or a single hop with specific parameters. +==== `Resource` vs. `Resources` + +The examples shown so far demonstrate how to side step Java's type erasure and convert a single JSON-formatted resource into a `Resource` object. But what if you get a collection like an *_embedded* HAL collection? + +One slight twak and you're set. + +[source,java] +---- +ParameterizedTypeReference> resourceParameterizedTypeReference = + new ParameterizedTypeReference>() {}; + +Resources itemResource = traverson.// + follow(rel("items")).// + toObject(resourceParameterizedTypeReference); +---- + +Instead of fetching a single resource, this one deserializes a collection into `Resources`. + [[client.link-discoverer]] === LinkDiscoverers @@ -408,3 +428,4 @@ Link link = discoverer.findLinkWithRel("foo", content); assertThat(link.getRel(), is("foo")); assertThat(link.getHref(), is("/foo/bar")); ---- +