Class HandlerMethodValidator
java.lang.Object
org.springframework.web.method.annotation.HandlerMethodValidator
- All Implemented Interfaces:
MethodValidator
MethodValidator
that
uses Bean Validation to validate @RequestMapping
method arguments.
Handles validation results by populating BindingResult
method
arguments with errors from beanResults
. Also, helps to determine parameter names for
@ModelAttribute
and @RequestBody
parameters.
- Since:
- 6.1
- Author:
- Rossen Stoyanchev
-
Method Summary
Modifier and TypeMethodDescriptionvoid
applyArgumentValidation
(Object target, Method method, MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Delegate toMethodValidator.validateArguments(java.lang.Object, java.lang.reflect.Method, org.springframework.core.MethodParameter[], java.lang.Object[], java.lang.Class<?>[])
and handle the validation result, by default raisingMethodValidationException
in case of errors.void
applyReturnValueValidation
(Object target, Method method, MethodParameter returnType, Object returnValue, Class<?>[] groups) Delegate toMethodValidator.validateReturnValue(java.lang.Object, java.lang.reflect.Method, org.springframework.core.MethodParameter, java.lang.Object, java.lang.Class<?>[])
and handle the validation result, by default raisingMethodValidationException
in case of errors.Class<?>[]
determineValidationGroups
(Object target, Method method) Determine the applicable validation groups.static MethodValidator
from
(WebBindingInitializer initializer, ParameterNameDiscoverer paramNameDiscoverer, Predicate<MethodParameter> modelAttributePredicate, Predicate<MethodParameter> requestParamPredicate) Static factory method to create aHandlerMethodValidator
when Bean Validation is enabled for use viaConfigurableWebBindingInitializer
, for example in Spring MVC or WebFlux config.validateArguments
(Object target, Method method, MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Validate the given method arguments and return validation results.validateReturnValue
(Object target, Method method, MethodParameter returnType, Object returnValue, Class<?>[] groups) Validate the given return value and return validation results.
-
Method Details
-
determineValidationGroups
Description copied from interface:MethodValidator
Determine the applicable validation groups. By default, obtained from an@Validated
annotation on the method, or on the class level.- Specified by:
determineValidationGroups
in interfaceMethodValidator
- Parameters:
target
- the target Objectmethod
- the target method- Returns:
- the applicable validation groups as a
Class
array
-
applyArgumentValidation
public void applyArgumentValidation(Object target, Method method, @Nullable MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Description copied from interface:MethodValidator
Delegate toMethodValidator.validateArguments(java.lang.Object, java.lang.reflect.Method, org.springframework.core.MethodParameter[], java.lang.Object[], java.lang.Class<?>[])
and handle the validation result, by default raisingMethodValidationException
in case of errors. Implementations may provide alternative handling, e.g. injectingErrors
into the method.- Specified by:
applyArgumentValidation
in interfaceMethodValidator
-
validateArguments
public MethodValidationResult validateArguments(Object target, Method method, @Nullable MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Description copied from interface:MethodValidator
Validate the given method arguments and return validation results.- Specified by:
validateArguments
in interfaceMethodValidator
- Parameters:
target
- the target Objectmethod
- the target methodparameters
- the parameters, if already created and availablearguments
- the candidate argument values to validategroups
- validation groups fromMethodValidator.determineValidationGroups(java.lang.Object, java.lang.reflect.Method)
- Returns:
- the result of validation
-
applyReturnValueValidation
public void applyReturnValueValidation(Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups) Description copied from interface:MethodValidator
Delegate toMethodValidator.validateReturnValue(java.lang.Object, java.lang.reflect.Method, org.springframework.core.MethodParameter, java.lang.Object, java.lang.Class<?>[])
and handle the validation result, by default raisingMethodValidationException
in case of errors. Implementations may provide alternative handling.- Specified by:
applyReturnValueValidation
in interfaceMethodValidator
-
validateReturnValue
public MethodValidationResult validateReturnValue(Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups) Description copied from interface:MethodValidator
Validate the given return value and return validation results.- Specified by:
validateReturnValue
in interfaceMethodValidator
- Parameters:
target
- the target Objectmethod
- the target methodreturnType
- the return parameter, if already created and availablereturnValue
- the return value to validategroups
- validation groups fromMethodValidator.determineValidationGroups(java.lang.Object, java.lang.reflect.Method)
- Returns:
- the result of validation
-
from
@Nullable public static MethodValidator from(@Nullable WebBindingInitializer initializer, @Nullable ParameterNameDiscoverer paramNameDiscoverer, Predicate<MethodParameter> modelAttributePredicate, Predicate<MethodParameter> requestParamPredicate) Static factory method to create aHandlerMethodValidator
when Bean Validation is enabled for use viaConfigurableWebBindingInitializer
, for example in Spring MVC or WebFlux config.
-