Interface MethodValidator

All Known Implementing Classes:
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 Details

    • determineValidationGroups

      Class<?>[] determineValidationGroups(Object target, Method method)
      Use this method to determine the validation groups.
      Parameters:
      target - the target Object
      method - the target method
      Returns:
      the applicable validation groups as a Class array
    • applyArgumentValidation

      default void applyArgumentValidation(Object target, Method method, @Nullable org.springframework.core.MethodParameter[] parameters, Object[] arguments, Class<?>[] groups)
      Validate the given method arguments and handle the result.
      Parameters:
      target - the target Object
      method - the target method
      parameters - the parameters, if already created and available
      arguments - the candidate argument values to validate
      groups - validation groups via determineValidationGroups(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 implements MethodValidationResult.
    • validateArguments

      MethodValidationResult validateArguments(Object target, Method method, @Nullable org.springframework.core.MethodParameter[] parameters, Object[] arguments, Class<?>[] groups)
      Validate the given method arguments and return validation results.
      Parameters:
      target - the target Object
      method - the target method
      parameters - the parameters, if already created and available
      arguments - the candidate argument values to validate
      groups - validation groups from determineValidationGroups(java.lang.Object, java.lang.reflect.Method)
      Returns:
      the result of validation
    • applyReturnValueValidation

      default void applyReturnValueValidation(Object target, Method method, @Nullable org.springframework.core.MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups)
      Validate the given return value and handle the results.
      Parameters:
      target - the target Object
      method - the target method
      returnType - the return parameter, if already created and available
      returnValue - the return value to validate
      groups - validation groups from determineValidationGroups(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 implements MethodValidationResult.
    • validateReturnValue

      MethodValidationResult validateReturnValue(Object target, Method method, @Nullable org.springframework.core.MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups)
      Validate the given return value and return the result of validation.
      Parameters:
      target - the target Object
      method - the target method
      returnType - the return parameter, if already created and available
      returnValue - the return value to validate
      groups - validation groups from determineValidationGroups(java.lang.Object, java.lang.reflect.Method)
      Returns:
      the result of validation