diff --git a/src/main/java/org/springframework/hateoas/hal/Jackson2HalModule.java b/src/main/java/org/springframework/hateoas/hal/Jackson2HalModule.java index 1f7af5a7..d5d88fb0 100644 --- a/src/main/java/org/springframework/hateoas/hal/Jackson2HalModule.java +++ b/src/main/java/org/springframework/hateoas/hal/Jackson2HalModule.java @@ -82,6 +82,7 @@ import com.fasterxml.jackson.databind.type.TypeFactory; * * @author Alexander Baetz * @author Oliver Gierke + * @author Jeffrey Walraven */ public class Jackson2HalModule extends SimpleModule { @@ -573,11 +574,19 @@ public class Jackson2HalModule extends SimpleModule { if (JsonToken.START_ARRAY.equals(jp.nextToken())) { while (!JsonToken.END_ARRAY.equals(jp.nextToken())) { link = jp.readValueAs(Link.class); - result.add(new Link(link.getHref(), relation)); + result.add(new Link(link.getHref(), relation) + .withHreflang(link.getHreflang()) + .withTitle(link.getTitle()) + .withType(link.getType()) + .withDeprecation(link.getDeprecation())); } } else { link = jp.readValueAs(Link.class); - result.add(new Link(link.getHref(), relation)); + result.add(new Link(link.getHref(), relation) + .withHreflang(link.getHreflang()) + .withTitle(link.getTitle()) + .withType(link.getType()) + .withDeprecation(link.getDeprecation())); } } diff --git a/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java b/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java index b4c9222c..6183e9ff 100755 --- a/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java @@ -52,6 +52,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; * @author Alexander Baetz * @author Oliver Gierke * @author Greg Turnquist + * @author Jeffrey Walraven */ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingIntegrationTest { @@ -118,6 +119,24 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg assertThat(write(resourceSupport)).isEqualTo(SINGLE_WITH_ALL_EXTRA_ATTRIBUTES); } + /** + * HAL doesn't support "media" so it's removed from the "expected" link. + * + * @see #699 + */ + @Test + public void deserializeAllExtraRFC5988Attributes() throws Exception { + + ResourceSupport expected = new ResourceSupport(); + expected.add(new Link("localhost", "self") // + .withHreflang("en") // + .withTitle("the title") // + .withType("the type") // + .withDeprecation("/customers/deprecated")); + + assertThat(read(SINGLE_WITH_ALL_EXTRA_ATTRIBUTES, ResourceSupport.class)).isEqualTo(expected); + } + @Test public void rendersWithOneExtraRFC5988Attribute() throws Exception { @@ -127,6 +146,18 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg assertThat(write(resourceSupport)).isEqualTo(SINGLE_WITH_ONE_EXTRA_ATTRIBUTES); } + /** + * @see #699 + */ + @Test + public void deserializeOneExtraRFC5988Attribute() throws Exception { + + ResourceSupport expected = new ResourceSupport(); + expected.add(new Link("localhost", "self").withTitle("the title")); + + assertThat(read(SINGLE_WITH_ONE_EXTRA_ATTRIBUTES, ResourceSupport.class)).isEqualTo(expected); + } + @Test public void deserializeSingleLink() throws Exception { ResourceSupport expected = new ResourceSupport();