Skip to content

Commit 7540e1b

Browse files
committed
#678 - Add 'profile' to Link.
Fully support HAL spec by adding "profile" as another optional attribute to `Link`. See: https://tools.ietf.org/html/draft-kelly-json-hal-08, https://tools.ietf.org/html/rfc5988
1 parent d5649c0 commit 7540e1b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/main/java/org/springframework/hateoas/Link.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class Link implements Serializable {
6868
private @Wither String title;
6969
private @Wither String type;
7070
private @Wither String deprecation;
71+
private @Wither String profile;
7172
private @JsonIgnore UriTemplate template;
7273
private @JsonIgnore List<Affordance> affordances;
7374

@@ -183,7 +184,7 @@ public Link andAffordances(List<Affordance> affordances) {
183184
public Link withAffordances(List<Affordance> affordances) {
184185

185186
return new Link(this.rel, this.href, this.hreflang, this.media, this.title, this.type, this.deprecation,
186-
this.template, affordances);
187+
this.profile, this.template, affordances);
187188
}
188189

189190
/**
@@ -298,6 +299,10 @@ public String toString() {
298299
linkString += ";deprecation=\"" + deprecation + "\"";
299300
}
300301

302+
if (profile != null) {
303+
linkString += ";profile=\"" + profile + "\"";
304+
}
305+
301306
return linkString;
302307
}
303308

@@ -349,6 +354,10 @@ public static Link valueOf(String element) {
349354
link = link.withDeprecation(attributes.get("deprecation"));
350355
}
351356

357+
if (attributes.containsKey("profile")) {
358+
link = link.withProfile(attributes.get("profile"));
359+
}
360+
352361
return link;
353362

354363
} else {

src/test/java/org/springframework/hateoas/LinkUnitTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ public void parsesRFC5988HeaderIntoLink() {
122122
+ "media=\"pdf\";" //
123123
+ "title=\"pdf customer copy\";" //
124124
+ "type=\"portable document\";" //
125-
+ "deprecation=\"http://example.com/customers/deprecated\"")) //
125+
+ "deprecation=\"http://example.com/customers/deprecated\";" //
126+
+ "profile=\"my-profile\"")) //
126127
.isEqualTo(new Link("/customer/1") //
127128
.withHreflang("en") //
128129
.withMedia("pdf") //
129130
.withTitle("pdf customer copy") //
130131
.withType("portable document") //
131-
.withDeprecation("http://example.com/customers/deprecated"));
132+
.withDeprecation("http://example.com/customers/deprecated")
133+
.withProfile("my-profile"));
132134
}
133135

134136
/**

0 commit comments

Comments
 (0)