#1496 - Improved HAL Link deserialization.
Configuring the Link.of(…) factory method as explicit creator method allows us to get rid of the wither chain previously required in HalLinkListDeserializer.
This commit is contained in:
@@ -600,8 +600,6 @@ public class Jackson2HalModule extends SimpleModule {
|
||||
public List<Link> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
|
||||
|
||||
List<Link> result = new ArrayList<>();
|
||||
String relation;
|
||||
Link link;
|
||||
|
||||
// links is an object, so we parse till we find its end.
|
||||
while (!JsonToken.END_OBJECT.equals(jp.nextToken())) {
|
||||
@@ -611,18 +609,14 @@ public class Jackson2HalModule extends SimpleModule {
|
||||
}
|
||||
|
||||
// save the relation in case the link does not contain it
|
||||
relation = jp.getText();
|
||||
String relation = jp.getText();
|
||||
|
||||
if (JsonToken.START_ARRAY.equals(jp.nextToken())) {
|
||||
while (!JsonToken.END_ARRAY.equals(jp.nextToken())) {
|
||||
link = jp.readValueAs(Link.class);
|
||||
result.add(Link.of(link.getHref(), relation).withHreflang(link.getHreflang()).withTitle(link.getTitle())
|
||||
.withType(link.getType()).withDeprecation(link.getDeprecation()));
|
||||
result.add(jp.readValueAs(Link.class).withRel(relation));
|
||||
}
|
||||
} else {
|
||||
link = jp.readValueAs(Link.class);
|
||||
result.add(Link.of(link.getHref(), relation).withHreflang(link.getHreflang()).withTitle(link.getTitle())
|
||||
.withType(link.getType()).withDeprecation(link.getDeprecation()));
|
||||
result.add(jp.readValueAs(Link.class).withRel(relation));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,11 @@ package org.springframework.hateoas.mediatype.hal;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.mediatype.hal.Jackson2HalModule.TrueOnlyBooleanSerializer;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
/**
|
||||
@@ -35,6 +37,11 @@ public abstract class LinkMixin extends Link {
|
||||
|
||||
private static final long serialVersionUID = 4720588561299667409L;
|
||||
|
||||
@JsonCreator
|
||||
public static Link of(@JsonProperty("href") String href) {
|
||||
return Link.of(href);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.Link#getHreflang()
|
||||
|
||||
Reference in New Issue
Block a user