Skip to content

Convert link with RFC5988 additional attributes #699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,21 @@ public List<Link> deserialize(JsonParser jp, DeserializationContext ctxt)
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())
.withMedia(link.getMedia())
.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())
.withMedia(link.getMedia())
.withTitle(link.getTitle())
.withType(link.getType())
.withDeprecation(link.getDeprecation()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
static final String LINK_WITH_TITLE = "{\"_links\":{\"ns:foobar\":{\"href\":\"target\",\"title\":\"Foobar's title!\"}}}";

static final String SINGLE_WITH_ONE_EXTRA_ATTRIBUTES = "{\"_links\":{\"self\":{\"href\":\"localhost\",\"title\":\"the title\"}}}";
static final String SINGLE_WITH_ALL_EXTRA_ATTRIBUTES = "{\"_links\":{\"self\":{\"href\":\"localhost\",\"hreflang\":\"en\",\"title\":\"the title\",\"type\":\"the type\",\"deprecation\":\"/customers/deprecated\"}}}";
static final String SINGLE_WITH_ALL_EXTRA_ATTRIBUTES = "{\"_links\":{\"self\":{\"href\":\"localhost\",\"hreflang\":\"en\",\"media\":\"the media\",\"title\":\"the title\",\"type\":\"the type\",\"deprecation\":\"/customers/deprecated\"}}}";

@Before
public void setUpModule() {
Expand Down Expand Up @@ -118,6 +118,20 @@ public void rendersAllExtraRFC5988Attributes() throws Exception {
assertThat(write(resourceSupport)).isEqualTo(SINGLE_WITH_ALL_EXTRA_ATTRIBUTES);
}

@Test
public void deserializeAllExtraRFC5988Attributes() throws Exception {

ResourceSupport expected = new ResourceSupport();
expected.add(new Link("localhost", "self") //
.withHreflang("en") //
.withTitle("the title") //
.withType("the type") //
.withMedia("the media") //
.withDeprecation("/customers/deprecated"));

assertThat(read(SINGLE_WITH_ALL_EXTRA_ATTRIBUTES, ResourceSupport.class)).isEqualTo(expected);
}

@Test
public void rendersWithOneExtraRFC5988Attribute() throws Exception {

Expand All @@ -127,6 +141,15 @@ public void rendersWithOneExtraRFC5988Attribute() throws Exception {
assertThat(write(resourceSupport)).isEqualTo(SINGLE_WITH_ONE_EXTRA_ATTRIBUTES);
}

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