Java Reference
In-Depth Information
p.prev , as the case may be. In each case, that will call the associated setter method and
assign the attribute to the link on the right-hand side.
A test of the structural links using the RESTClient looks like this:
def 'structural and transitional links for kirk are correct'() {
when:
def response = client.get(path: 'people/3')
then:
'James Kirk' == "$response.data.first $response.data.last"
response.getHeaders('Link').each { println it }
assert response.data.prev.href == 'http://localhost:1234/people/2'
assert response.data.self.href == 'http://localhost:1234/people/3'
assert response.data.next.href == 'http://localhost:1234/people/4'
}
Theresponsewrapsa Person instance, accessed bycalling getData .Thentheindividu-
al links are retrieved as the prev , self , and next properties. The result is a Link in-
stance whose getHref method can be used to verify the links.
There's only one problem, and it's more of a nuisance than anything else. In the Rotten To-
matoes example at the beginning of the hypermedia section, the links were not top-level at-
tributes of the movies. Instead, each movie representation contained a JSON object whose
key was links , and which contained the list of individual links and relations. Here's the
snippet from the Rotten Tomatoes response:
"links": {
"self": "http://api.rottentomatoes.com/.../771190753.json",
"cast": "http://api.rottentomatoes.com/.../771190753/cast.json",
"clips": "http://api.rottentomatoes.com/.../771190753/clips.json",
"reviews": "http://api.rottentomatoes.com/.../771190753/reviews.json",
"similar": "http://api.rottentomatoes.com/.../771190753/similar.json"
}
In the JAX-RS approach using the serializer, the relation is the attribute name. What if I
want to make a collection of links as shown in the movie example? For that I need to take
control of the serialization process.
Search WWH ::




Custom Search