From 63e1c8440cdd9c7067b022b9197728d055506c8e Mon Sep 17 00:00:00 2001 From: Greg Turnquist Date: Sun, 5 Apr 2020 16:11:30 -0500 Subject: [PATCH 1/2] HATEOAS-1260 - Prepare branch --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 37a7151c5..fccbdaa8c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.hateoas spring-hateoas - 1.1.0.BUILD-SNAPSHOT + 1.1.0.HATEOAS-1260-SNAPSHOT Spring HATEOAS https://github.com/spring-projects/spring-hateoas From bca0bc133bd3862481b792b67e7c9beb488a5744 Mon Sep 17 00:00:00 2001 From: Greg Turnquist Date: Sun, 5 Apr 2020 16:11:52 -0500 Subject: [PATCH 2/2] #1260 - Adjust CustomHypermediaType so it produces HAL-like JSON. By having this custom hypermedia type register ALL the parts of the HAL Jackson module, it provides a better example to users that wish to serve a custom media type that is HAL-like. Related issues: #1259, #1253 --- .../hateoas/support/CustomHypermediaType.java | 8 ++++++++ .../springframework/hateoas/config/webflux-frodo.json | 11 ++++++----- .../springframework/hateoas/config/webmvc-frodo.json | 11 ++++++----- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/springframework/hateoas/support/CustomHypermediaType.java b/src/test/java/org/springframework/hateoas/support/CustomHypermediaType.java index f66ee67de..1edec25fd 100644 --- a/src/test/java/org/springframework/hateoas/support/CustomHypermediaType.java +++ b/src/test/java/org/springframework/hateoas/support/CustomHypermediaType.java @@ -19,6 +19,11 @@ import java.util.List; import org.springframework.hateoas.config.HypermediaMappingInformation; +import org.springframework.hateoas.mediatype.MessageResolver; +import org.springframework.hateoas.mediatype.hal.CurieProvider; +import org.springframework.hateoas.mediatype.hal.Jackson2HalModule; +import org.springframework.hateoas.mediatype.hal.Jackson2HalModule.HalHandlerInstantiator; +import org.springframework.hateoas.server.core.EvoInflectorLinkRelationProvider; import org.springframework.http.MediaType; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -47,6 +52,9 @@ public List getMediaTypes() { @Override public ObjectMapper configureObjectMapper(ObjectMapper mapper) { + mapper.registerModule(new Jackson2HalModule()); + mapper.setHandlerInstantiator(new HalHandlerInstantiator(new EvoInflectorLinkRelationProvider(), + CurieProvider.NONE, MessageResolver.DEFAULTS_ONLY)); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.enable(SerializationFeature.INDENT_OUTPUT); diff --git a/src/test/resources/org/springframework/hateoas/config/webflux-frodo.json b/src/test/resources/org/springframework/hateoas/config/webflux-frodo.json index c7bb07c9d..d9e29209a 100644 --- a/src/test/resources/org/springframework/hateoas/config/webflux-frodo.json +++ b/src/test/resources/org/springframework/hateoas/config/webflux-frodo.json @@ -1,8 +1,9 @@ { "name" : "Frodo Baggins", "role" : "ring bearer", - "links" : [ { - "rel" : "self", - "href" : "http://localhost/employees/1" - } ] -} \ No newline at end of file + "_links" : { + "self" : { + "href" : "http://localhost/employees/1" + } + } +} diff --git a/src/test/resources/org/springframework/hateoas/config/webmvc-frodo.json b/src/test/resources/org/springframework/hateoas/config/webmvc-frodo.json index c7bb07c9d..d9e29209a 100644 --- a/src/test/resources/org/springframework/hateoas/config/webmvc-frodo.json +++ b/src/test/resources/org/springframework/hateoas/config/webmvc-frodo.json @@ -1,8 +1,9 @@ { "name" : "Frodo Baggins", "role" : "ring bearer", - "links" : [ { - "rel" : "self", - "href" : "http://localhost/employees/1" - } ] -} \ No newline at end of file + "_links" : { + "self" : { + "href" : "http://localhost/employees/1" + } + } +}