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 @Nullable [] parameters, @Nullable Object[] arguments, Class<?>[] groups) Delegate tovalidateArguments(Object, Method, MethodParameter[], Object[], Class[])
and handle the validation result, by default raisingMethodValidationException
in case of errors.default void
applyReturnValueValidation
(Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups) Delegate tovalidateReturnValue(Object, Method, MethodParameter, Object, 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 @Nullable [] parameters, @Nullable Object[] arguments, Class<?>[] groups) Validate the given method arguments and return validation results.validateReturnValue
(Object target, Method method, @Nullable MethodParameter returnType, @Nullable 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, MethodParameter @Nullable [] parameters, @Nullable 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(Object, Method)
- Returns:
- the result of validation
-
applyArgumentValidation
default void applyArgumentValidation(Object target, Method method, MethodParameter @Nullable [] parameters, @Nullable Object[] arguments, Class<?>[] groups) Delegate tovalidateArguments(Object, Method, MethodParameter[], Object[], 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(Object, Method)
- Returns:
- the result of validation
-
applyReturnValueValidation
default void applyReturnValueValidation(Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups) Delegate tovalidateReturnValue(Object, Method, MethodParameter, Object, 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.
-