Browse Source

Return consistent collection type for matrix variables

See gh-31483
pull/31491/head
Bernie Schelberg 1 year ago committed by Stéphane Nicoll
parent
commit
ea30c8fb5b
  1. 2
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMapMethodArgumentResolver.java
  2. 12
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMapMethodArgumentResolverTests.java

2
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMapMethodArgumentResolver.java

@ -69,7 +69,7 @@ public class MatrixVariableMapMethodArgumentResolver implements HandlerMethodArg @@ -69,7 +69,7 @@ public class MatrixVariableMapMethodArgumentResolver implements HandlerMethodArg
HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
if (CollectionUtils.isEmpty(matrixVariables)) {
return Collections.emptyMap();
return (isSingleValueMap(parameter) ? Collections.emptyMap() : new LinkedMultiValueMap<>(0));
}
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();

12
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMapMethodArgumentResolverTests.java

@ -155,6 +155,18 @@ public class MatrixVariablesMapMethodArgumentResolverTests { @@ -155,6 +155,18 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
assertThat(map).isEqualTo(Collections.emptyMap());
}
@Test
public void resolveMultiValueMapArgumentNoParams() throws Exception {
MethodParameter param = this.testMethod.annot(matrixAttribute().noPathVar())
.arg(MultiValueMap.class, String.class, String.class);
Object result = this.resolver.resolveArgument(param, this.mavContainer, this.webRequest, null);
//noinspection unchecked
assertThat(result).isInstanceOfSatisfying(MultiValueMap.class, map -> assertThat(map).isEmpty());
}
@Test
public void resolveArgumentNoMatch() throws Exception {
MultiValueMap<String, String> params2 = getVariablesFor("planes");

Loading…
Cancel
Save