From 0a94dce41dd032d5f6c153863c52b2dcd1dd0e91 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Thu, 14 Dec 2023 16:33:50 +0000 Subject: [PATCH] Improve HandlerMethod check when method validation applies Method validation needs to be used for a container such as a List or Map, but until now we were only checking for a List container. Moreover, in gh-31530 we improved method validation to also cover any Collection. This change aligns with HandlerMethod check for when method validation applies with the underlying ability of method validation. --- .../java/org/springframework/web/method/HandlerMethod.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java b/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java index 5474a1ce10..285a597c82 100644 --- a/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java +++ b/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java @@ -18,7 +18,8 @@ package org.springframework.web.method; import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import java.util.List; +import java.util.Collection; +import java.util.Map; import java.util.StringJoiner; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -402,7 +403,8 @@ public class HandlerMethod extends AnnotatedMethod { } else { Class type = parameter.getParameterType(); - if (merged.stream().anyMatch(VALID_PREDICATE) && List.class.isAssignableFrom(type)) { + if (merged.stream().anyMatch(VALID_PREDICATE) && + (Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type))) { return true; } }