Interface MethodValidator
- All Known Implementing Classes:
DefaultMethodValidator,HandlerMethodValidator
public interface MethodValidator
Contract to apply method validation without directly using
MethodValidationAdapter. For use in components where Jakarta Bean
Validation is an optional dependency and may or may not be present on the
classpath. If that's not a concern, use MethodValidationAdapter
directly.- Since:
- 6.1
- Author:
- Rossen Stoyanchev
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionClass<?>[]determineValidationGroups(Object target, Method method) Use this method determine the validation groups to pass intovalidateArguments(Object, Method, MethodParameter[], Object[], Class[])andvalidateReturnValue(Object, Method, MethodParameter, Object, Class[]).voidvalidateArguments(Object target, Method method, MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Validate the given method arguments and return the result of validation.voidvalidateReturnValue(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 determine the validation groups to pass intovalidateArguments(Object, Method, MethodParameter[], Object[], Class[])andvalidateReturnValue(Object, Method, MethodParameter, Object, Class[]).- Parameters:
target- the target Objectmethod- the target method- Returns:
- the applicable validation groups as a
Classarray - See Also:
-
validateArguments
void validateArguments(Object target, Method method, @Nullable MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Validate the given method arguments and return the result of validation.- Parameters:
target- the target Objectmethod- the target methodparameters- the parameters, if already created and availablearguments- the candidate argument values to validategroups- groups for validation determined viadetermineValidationGroups(Object, Method)- Throws:
MethodValidationException- should be raised in case of validation errors unless the implementation handles those errors otherwise (e.g. by injectingBindingResultinto the method).
-
validateReturnValue
void 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- groups for validation determined viadetermineValidationGroups(Object, Method)- Throws:
MethodValidationException- in case of validation errors
-