diff --git a/src/main/java/org/springframework/hateoas/Link.java b/src/main/java/org/springframework/hateoas/Link.java index e6347a60..c3bdadad 100755 --- a/src/main/java/org/springframework/hateoas/Link.java +++ b/src/main/java/org/springframework/hateoas/Link.java @@ -50,7 +50,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; @JsonIgnoreProperties(value = "templated", ignoreUnknown = true) @AllArgsConstructor(access = AccessLevel.PACKAGE) @Getter -@EqualsAndHashCode(of = { "rel", "href", "hreflang", "media", "title", "deprecation", "affordances" }) +@EqualsAndHashCode(of = { "rel", "href", "hreflang", "media", "title", "type", "deprecation", "profile", "name", "affordances" }) public class Link implements Serializable { private static final long serialVersionUID = -9037755944661782121L; @@ -100,6 +100,7 @@ public class Link implements Serializable { private @Wither String type; private @Wither String deprecation; private @Wither String profile; + private @Wither String name; private @JsonIgnore UriTemplate template; private @JsonIgnore List affordances; @@ -257,7 +258,7 @@ public class Link implements Serializable { public Link withAffordances(List affordances) { return new Link(this.rel, this.href, this.hreflang, this.media, this.title, this.type, this.deprecation, - this.profile, this.template, affordances); + this.profile, this.name, this.template, affordances); } /** @@ -324,11 +325,11 @@ public class Link implements Serializable { private UriTemplate getUriTemplate() { - if (template == null) { + if (this.template == null) { this.template = new UriTemplate(href); } - return template; + return this.template; } /* @@ -364,6 +365,10 @@ public class Link implements Serializable { linkString += ";profile=\"" + profile + "\""; } + if (name != null) { + linkString += ";name=\"" + name + "\""; + } + return linkString; } @@ -418,6 +423,10 @@ public class Link implements Serializable { link = link.withProfile(attributes.get("profile")); } + if (attributes.containsKey("name")) { + link = link.withName(attributes.get("name")); + } + return link; } else { diff --git a/src/main/java/org/springframework/hateoas/hal/LinkMixin.java b/src/main/java/org/springframework/hateoas/hal/LinkMixin.java index c9ec76d1..47eba5a4 100644 --- a/src/main/java/org/springframework/hateoas/hal/LinkMixin.java +++ b/src/main/java/org/springframework/hateoas/hal/LinkMixin.java @@ -67,6 +67,22 @@ public abstract class LinkMixin extends Link { @JsonInclude(Include.NON_NULL) public abstract String getDeprecation(); + /* + * (non-Javadoc) + * @see org.springframework.hateoas.Link#getProfile() + */ + @Override + @JsonInclude(Include.NON_NULL) + public abstract String getProfile(); + + /* + * (non-Javadoc) + * @see org.springframework.hateoas.Link#getName() + */ + @Override + @JsonInclude(Include.NON_NULL) + public abstract String getName(); + /* * (non-Javadoc) * @see org.springframework.hateoas.Link#isTemplate() diff --git a/src/test/java/org/springframework/hateoas/LinkUnitTest.java b/src/test/java/org/springframework/hateoas/LinkUnitTest.java index be4ac57e..94a2deab 100755 --- a/src/test/java/org/springframework/hateoas/LinkUnitTest.java +++ b/src/test/java/org/springframework/hateoas/LinkUnitTest.java @@ -144,13 +144,16 @@ public class LinkUnitTest { + "title=\"pdf customer copy\";" // + "type=\"portable document\";" // + "deprecation=\"http://example.com/customers/deprecated\";" // - + "profile=\"my-profile\"")) // + + "profile=\"my-profile\";" // + + "name=\"my-name\";")) // .isEqualTo(new Link("/customer/1") // .withHreflang("en") // .withMedia("pdf") // .withTitle("pdf customer copy") // .withType("portable document") // - .withDeprecation("http://example.com/customers/deprecated").withProfile("my-profile")); + .withDeprecation("http://example.com/customers/deprecated") // + .withProfile("my-profile") // + .withName("my-name")); }); }