Improve check to skip bean validation in DataBinder

DataBinder should skip any jakarta.validation.Validator yielding
to method validation when that is expected. This change improves
the check to skip by unwrapping the validator from in a
SmartValidator before checking if it is for bean validation.

Closes gh-31711
This commit is contained in:
rstoyanchev
2023-12-18 15:23:30 +00:00
parent 0a94dce41d
commit bec7210b4b
4 changed files with 214 additions and 2 deletions

View File

@@ -22,6 +22,7 @@ import org.springframework.core.MethodParameter;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.validation.DataBinder;
import org.springframework.validation.SmartValidator;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.context.request.NativeWebRequest;
@@ -148,7 +149,8 @@ public class DefaultDataBinderFactory implements WebDataBinderFactory {
public static void initBinder(DataBinder binder, MethodParameter parameter) {
for (Annotation annotation : parameter.getParameterAnnotations()) {
if (annotation.annotationType().getName().equals("jakarta.validation.Valid")) {
binder.setExcludedValidators(validator -> validator instanceof jakarta.validation.Validator);
binder.setExcludedValidators(v -> v instanceof jakarta.validation.Validator ||
v instanceof SmartValidator sv && sv.unwrap(jakarta.validation.Validator.class) != null);
}
}
}