From e5b03862d300d5669c52f3f81727f281d798b1e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Tue, 4 Feb 2025 12:34:22 +0100 Subject: [PATCH] Polish "Add property to configure Spring MVC default content types" See gh-44040 --- .../web/servlet/WebMvcProperties.java | 28 +++++++++---------- .../servlet/WebMvcAutoConfigurationTests.java | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java index 3459190ef6..8de413f29d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java @@ -308,6 +308,11 @@ public class WebMvcProperties { */ private boolean favorParameter = false; + /** + * Query parameter name to use when "favor-parameter" is enabled. + */ + private String parameterName; + /** * Map file extensions to media types for content negotiation. For instance, yml * to text/yaml. @@ -315,12 +320,7 @@ public class WebMvcProperties { private Map mediaTypes = new LinkedHashMap<>(); /** - * Query parameter name to use when "favor-parameter" is enabled. - */ - private String parameterName; - - /** - * The default content types to be used when no specific content type is + * List of default content types to be used when no specific content type is * requested. */ private List defaultContentTypes = new ArrayList<>(); @@ -333,14 +333,6 @@ public class WebMvcProperties { this.favorParameter = favorParameter; } - public Map getMediaTypes() { - return this.mediaTypes; - } - - public void setMediaTypes(Map mediaTypes) { - this.mediaTypes = mediaTypes; - } - public String getParameterName() { return this.parameterName; } @@ -349,6 +341,14 @@ public class WebMvcProperties { this.parameterName = parameterName; } + public Map getMediaTypes() { + return this.mediaTypes; + } + + public void setMediaTypes(Map mediaTypes) { + this.mediaTypes = mediaTypes; + } + public List getDefaultContentTypes() { return this.defaultContentTypes; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java index d4eb2ddd23..27f62d81e6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java @@ -580,7 +580,7 @@ class WebMvcAutoConfigurationTests { } @Test - void defaultContentTypes() { + void customDefaultContentTypes() { this.contextRunner .withPropertyValues("spring.mvc.contentnegotiation.default-content-types:application/json,application/xml") .run((context) -> {