From 4f214bbbad4f05972a3b5906e2ca6bb9278335c2 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Fri, 17 Jan 2025 16:41:15 +0100 Subject: [PATCH] Add support for offical, IANA-registered media type for HAL. Fixes GH-2453. --- .../data/rest/webmvc/RepositoryRestHandlerMapping.java | 2 ++ .../rest/webmvc/config/RepositoryRestMvcConfiguration.java | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMapping.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMapping.java index b40d759d1..dadeed048 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMapping.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMapping.java @@ -189,6 +189,8 @@ public class RepositoryRestHandlerMapping extends BasePathAwareHandlerMapping { Set mediaTypes = new LinkedHashSet(); mediaTypes.add(configuration.getDefaultMediaType().toString()); + mediaTypes.add(MediaTypes.HAL_JSON_VALUE); + mediaTypes.add(MediaTypes.VND_HAL_JSON_VALUE); mediaTypes.add(MediaType.APPLICATION_JSON_VALUE); mediaTypes.add(MediaTypes.HAL_FORMS_JSON_VALUE); diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.java index f16a5dcbf..7496522dc 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.java @@ -575,6 +575,7 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon ArrayList mediaTypes = new ArrayList<>(); mediaTypes.add(MediaTypes.HAL_JSON); + mediaTypes.add(MediaTypes.VND_HAL_JSON); // Enable returning HAL if application/json is asked if it's configured to be the default type if (repositoryRestConfiguration.useHalAsDefaultJsonMediaType()) { @@ -809,7 +810,8 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon messageConverters.add(alpsJsonHttpMessageConverter); } - if (repositoryRestConfiguration.getDefaultMediaType().equals(MediaTypes.HAL_JSON)) { + if (List.of(MediaTypes.HAL_JSON, MediaTypes.VND_HAL_JSON) + .contains(repositoryRestConfiguration.getDefaultMediaType())) { messageConverters.add(halJacksonHttpMessageConverter); messageConverters.add(jacksonHttpMessageConverter); } else {