Skip to content

Commit 984f90f

Browse files
committed
Merge branch '1.0.x'
2 parents ae53a4e + 032b7b5 commit 984f90f

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/HalLinkExtractor.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2015 the original author or authors.
2+
* Copyright 2014-2016 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.
@@ -54,9 +54,9 @@ private static List<Link> convertToLinks(Object object, String rel) {
5454
List<Link> links = new ArrayList<>();
5555
if (object instanceof Collection) {
5656
@SuppressWarnings("unchecked")
57-
Collection<Object> hrefObjects = (Collection<Object>) object;
58-
for (Object hrefObject : hrefObjects) {
59-
maybeAddLink(maybeCreateLink(rel, hrefObject), links);
57+
Collection<Object> possibleLinkObjects = (Collection<Object>) object;
58+
for (Object possibleLinkObject : possibleLinkObjects) {
59+
maybeAddLink(maybeCreateLink(rel, possibleLinkObject), links);
6060
}
6161
}
6262
else {
@@ -65,9 +65,12 @@ private static List<Link> convertToLinks(Object object, String rel) {
6565
return links;
6666
}
6767

68-
private static Link maybeCreateLink(String rel, Object possibleHref) {
69-
if (possibleHref instanceof String) {
70-
return new Link(rel, (String) possibleHref);
68+
private static Link maybeCreateLink(String rel, Object possibleLinkObject) {
69+
if (possibleLinkObject instanceof Map) {
70+
Object hrefObject = ((Map<?, ?>) possibleLinkObject).get("href");
71+
if (hrefObject instanceof String) {
72+
return new Link(rel, (String) hrefObject);
73+
}
7174
}
7275
return null;
7376
}

spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinkExtractorsPayloadTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2015 the original author or authors.
2+
* Copyright 2014-2016 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.
@@ -53,7 +53,7 @@ public class LinkExtractorsPayloadTests {
5353

5454
private final String linkType;
5555

56-
@Parameters
56+
@Parameters(name = "{1}")
5757
public static Collection<Object[]> data() {
5858
return Arrays.asList(new Object[] { new HalLinkExtractor(), "hal" },
5959
new Object[] { new AtomLinkExtractor(), "atom" });
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
2-
"_links": {
3-
"alpha": ["http://alpha.example.com/one", "http://alpha.example.com/two"]
2+
"links": {
3+
"alpha": [{
4+
"href": "http://alpha.example.com/one"
5+
}, {
6+
"href": "http://alpha.example.com/two"
7+
}]
48
}
59
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"_links": {
3-
"alpha": "http://alpha.example.com",
4-
"bravo": "http://bravo.example.com"
3+
"alpha": {
4+
"href": "http://alpha.example.com"
5+
},
6+
"bravo": {
7+
"href": "http://bravo.example.com"
8+
}
59
}
610
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"_links": {
3-
"alpha": ["http://alpha.example.com/one", "http://alpha.example.com/two"]
3+
"alpha": [{
4+
"href": "http://alpha.example.com/one"
5+
}, {
6+
"href": "http://alpha.example.com/two"
7+
}]
48
}
59
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"_links": {
3-
"alpha": "http://alpha.example.com"
3+
"alpha": {
4+
"href": "http://alpha.example.com"
5+
}
46
}
57
}

0 commit comments

Comments
 (0)