Interface MethodValidator
- All Known Implementing Classes:
HandlerMethodValidator
,MethodValidationAdapter
public interface MethodValidator
Contract to apply method validation and handle the results.
Exposes methods that return
MethodValidationResult
, and methods that
handle the results, by default raising MethodValidationException
.- Since:
- 6.1
- Author:
- Rossen Stoyanchev
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
applyArgumentValidation
(Object target, Method method, MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Delegate tovalidateArguments(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.default void
applyReturnValueValidation
(Object target, Method method, MethodParameter returnType, Object returnValue, Class<?>[] groups) Delegate tovalidateReturnValue(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.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
Determine the applicable validation groups. By default, obtained from an@Validated
annotation on the method, or on the class level.- Parameters:
target
- the target Objectmethod
- the target method- Returns:
- the applicable validation groups as a
Class
array
-
validateArguments
MethodValidationResult validateArguments(Object target, Method method, @Nullable MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Validate the given method arguments and return validation results.- Parameters:
target
- the target Objectmethod
- the target methodparameters
- the parameters, if already created and availablearguments
- the candidate argument values to validategroups
- validation groups fromdetermineValidationGroups(java.lang.Object, java.lang.reflect.Method)
- Returns:
- the result of validation
-
applyArgumentValidation
default void applyArgumentValidation(Object target, Method method, @Nullable MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Delegate tovalidateArguments(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, for example, injectingErrors
into the method.- Throws:
MethodValidationException
- in case of unhandled errors.
-
validateReturnValue
MethodValidationResult validateReturnValue(Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups) Validate the given return value and return validation results.- Parameters:
target
- the target Objectmethod
- the target methodreturnType
- the return parameter, if already created and availablereturnValue
- the return value to validategroups
- validation groups fromdetermineValidationGroups(java.lang.Object, java.lang.reflect.Method)
- Returns:
- the result of validation
-
applyReturnValueValidation
default void applyReturnValueValidation(Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups) Delegate tovalidateReturnValue(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.- Throws:
MethodValidationException
- in case of unhandled errors.
-