#699 - Render additional RFC5988 attributions in HAL.

This commit is contained in:
Jeffrey Walraven
2018-02-16 20:51:16 -05:00
committed by Greg Turnquist
parent 1e32bb5d2d
commit ba1dae383c
2 changed files with 42 additions and 2 deletions

View File

@@ -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()));
}
}

View File

@@ -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();