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) Validate the given method arguments and handle the result.default void
applyReturnValueValidation
(Object target, Method method, MethodParameter returnType, Object returnValue, Class<?>[] groups) Validate the given return value and handle the results.Class<?>[]
determineValidationGroups
(Object target, Method method) Use this method to determine the 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 the result of validation.
-
Method Details
-
determineValidationGroups
Use this method to determine the validation groups.- Parameters:
target
- the target Objectmethod
- the target method- Returns:
- the applicable validation groups as a
Class
array
-
applyArgumentValidation
default void applyArgumentValidation(Object target, Method method, @Nullable MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Validate the given method arguments and handle the result.- Parameters:
target
- the target Objectmethod
- the target methodparameters
- the parameters, if already created and availablearguments
- the candidate argument values to validategroups
- validation groups viadetermineValidationGroups(java.lang.Object, java.lang.reflect.Method)
- Throws:
MethodValidationException
- raised by default in case of validation errors. Implementations may provide alternative handling, possibly not raise an exception but for example inject errors into the method, or raise a different exception, one that also implementsMethodValidationResult
.
-
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
-
applyReturnValueValidation
default void applyReturnValueValidation(Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups) Validate the given return value and handle the 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)
- Throws:
MethodValidationException
- raised by default in case of validation errors. Implementations may provide alternative handling, or raise a different exception, one that also implementsMethodValidationResult
.
-
validateReturnValue
MethodValidationResult validateReturnValue(Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups) Validate the given return value and return the result of validation.- 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
-