diff --git a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsAffordanceModel.java b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsAffordanceModel.java index 1160f982..23dbaea7 100644 --- a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsAffordanceModel.java +++ b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsAffordanceModel.java @@ -19,14 +19,13 @@ import lombok.extern.slf4j.Slf4j; import java.beans.PropertyDescriptor; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.TreeMap; +import java.util.stream.Collectors; import org.springframework.beans.BeanUtils; import org.springframework.core.MethodParameter; @@ -73,18 +72,9 @@ class HalFormsAffordanceModel implements AffordanceModel { */ public List getProperties() { - List halFormsProperties = new ArrayList(); - - for (Entry> entry : this.properties.entrySet()) { - - HalFormsProperty property = HalFormsProperty// - .named(entry.getKey())// - .withRequired(required); - - halFormsProperties.add(property); - } - - return halFormsProperties; + return properties.entrySet().stream() // + .map(entry -> entry.getKey()) // + .map(key -> HalFormsProperty.named(key).withRequired(required)).collect(Collectors.toList()); } public String getPath() { @@ -136,7 +126,7 @@ class HalFormsAffordanceModel implements AffordanceModel { LOG.debug("Gathering details about " + method.getDeclaringClass().getCanonicalName() + "." + method.getName()); - Map> properties = new TreeMap>(); + Map> properties = new TreeMap<>(); MethodParameters parameters = new MethodParameters(method); for (MethodParameter parameter : parameters.getParametersWith(RequestBody.class)) { diff --git a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsConfiguration.java b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsConfiguration.java index 9604707d..d22b5808 100644 --- a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsConfiguration.java +++ b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsConfiguration.java @@ -63,5 +63,4 @@ public class HalFormsConfiguration { throw new IllegalStateException("Don't know how to translate " + this); } - } diff --git a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsDeserializers.java b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsDeserializers.java index 59f1f377..e7d4a3b3 100644 --- a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsDeserializers.java +++ b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsDeserializers.java @@ -99,12 +99,8 @@ class HalFormsDeserializers { public JsonDeserializer createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { - if (property != null) { - JavaType vc = property.getType().getContentType(); - return new HalFormsResourcesDeserializer(vc); - } else { - return new HalFormsResourcesDeserializer(ctxt.getContextualType()); - } + return new HalFormsResourcesDeserializer( + property == null ? ctxt.getContextualType() : property.getType().getContentType()); } } diff --git a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsDocument.java b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsDocument.java index fa8492be..d1e5fdf4 100644 --- a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsDocument.java +++ b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsDocument.java @@ -61,8 +61,7 @@ public class HalFormsDocument { @Wither(AccessLevel.PRIVATE) // private T resource; - @JsonInclude(Include.NON_EMPTY) - @JsonIgnore // + @JsonInclude(Include.NON_EMPTY) @JsonIgnore // @Wither(AccessLevel.PRIVATE) // private Collection resources; @@ -87,8 +86,7 @@ public class HalFormsDocument { private Map templates; private HalFormsDocument() { - this(null, null, Collections. emptyMap(), null, Collections. emptyList(), - Collections. emptyMap()); + this(null, null, Collections.emptyMap(), null, Collections.emptyList(), Collections.emptyMap()); } /** @@ -120,7 +118,7 @@ public class HalFormsDocument { * @return */ public static HalFormsDocument empty() { - return new HalFormsDocument(); + return new HalFormsDocument<>(); } /** @@ -157,7 +155,7 @@ public class HalFormsDocument { Assert.notNull(link, "Link must not be null!"); - List links = new ArrayList(this.links); + List links = new ArrayList<>(this.links); links.add(link); return new HalFormsDocument(resource, resources, embedded, pageMetadata, links, templates); @@ -175,7 +173,7 @@ public class HalFormsDocument { Assert.hasText(name, "Template name must not be null or empty!"); Assert.notNull(template, "Template must not be null!"); - Map templates = new HashMap(this.templates); + Map templates = new HashMap<>(this.templates); templates.put(name, template); return new HalFormsDocument(resource, resources, embedded, pageMetadata, links, templates); diff --git a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsSerializers.java b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsSerializers.java index 439a4fa9..f5f33f0f 100644 --- a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsSerializers.java +++ b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsSerializers.java @@ -192,7 +192,8 @@ class HalFormsSerializers { Map templates = new HashMap(); if (resource.hasLink(Link.REL_SELF)) { - for (Affordance affordance : resource.getLink(Link.REL_SELF).map(Link::getAffordances).orElse(Collections.emptyList())) { + for (Affordance affordance : resource.getLink(Link.REL_SELF).map(Link::getAffordances) + .orElse(Collections.emptyList())) { HalFormsAffordanceModel model = affordance.getAffordanceModel(MediaTypes.HAL_FORMS_JSON); @@ -224,6 +225,7 @@ class HalFormsSerializers { private static void validate(ResourceSupport resource, Affordance affordance, HalFormsAffordanceModel model) { try { + Optional selfLink = resource.getLink(Link.REL_SELF); URI selfLinkUri = new URI(selfLink.map(link -> link.expand().getHref()).orElse("")); diff --git a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsTemplate.java b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsTemplate.java index c630f628..a91e4c9f 100644 --- a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsTemplate.java +++ b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsTemplate.java @@ -26,7 +26,6 @@ import lombok.experimental.Wither; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; import org.springframework.hateoas.hal.forms.HalFormsDeserializers.MediaTypesDeserializer; import org.springframework.http.HttpMethod; @@ -39,7 +38,6 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; /** * Value object for a HAL-FORMS template. Describes the available state transition details. @@ -67,7 +65,7 @@ public class HalFormsTemplate { private List contentTypes; private HalFormsTemplate() { - this(null, null, Collections. emptyList(), Collections. emptyList()); + this(null, null, Collections.emptyList(), Collections.emptyList()); } public static HalFormsTemplate forMethod(HttpMethod httpMethod) { @@ -84,7 +82,7 @@ public class HalFormsTemplate { Assert.notNull(property, "Property must not be null!"); - ArrayList properties = new ArrayList(this.properties); + List properties = new ArrayList<>(this.properties); properties.add(property); return new HalFormsTemplate(title, httpMethod, properties, contentTypes); @@ -100,7 +98,7 @@ public class HalFormsTemplate { Assert.notNull(mediaType, "Media type must not be null!"); - ArrayList contentTypes = new ArrayList(this.contentTypes); + List contentTypes = new ArrayList<>(this.contentTypes); contentTypes.add(mediaType); return new HalFormsTemplate(title, httpMethod, properties, contentTypes); diff --git a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsWebMvcConfigurer.java b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsWebMvcConfigurer.java index 7959e88d..699fdf47 100644 --- a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsWebMvcConfigurer.java +++ b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsWebMvcConfigurer.java @@ -19,7 +19,7 @@ import java.util.List; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import com.fasterxml.jackson.databind.ObjectMapper; @@ -30,7 +30,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; * @author Greg Turnquist */ @Configuration -public class HalFormsWebMvcConfigurer extends WebMvcConfigurerAdapter { +public class HalFormsWebMvcConfigurer implements WebMvcConfigurer { /* * (non-Javadoc)