Package org.springframework.validation.method

# 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 Summary

Modifier and Type
Method
Description
`default void`
`applyArgumentValidation(Object target, Method method, org.springframework.core.MethodParameter[] parameters, Object[] arguments, Class<?>[] groups)`
Delegate to `validateArguments(java.lang.Object, java.lang.reflect.Method, org.springframework.core.MethodParameter[], java.lang.Object[], java.lang.Class<?>[])` and handle the validation result, by default raising `MethodValidationException` in case of errors.
`default void`
`applyReturnValueValidation(Object target, Method method, org.springframework.core.MethodParameter returnType, Object returnValue, Class<?>[] groups)`
Delegate to `validateReturnValue(java.lang.Object, java.lang.reflect.Method, org.springframework.core.MethodParameter, java.lang.Object, java.lang.Class<?>[])` and handle the validation result, by default raising `MethodValidationException` in case of errors.
`Class<?>[]`
`determineValidationGroups(Object target, Method method)`
Determine the applicable validation groups.
`MethodValidationResult`
`validateArguments(Object target, Method method, org.springframework.core.MethodParameter[] parameters, Object[] arguments, Class<?>[] groups)`
Validate the given method arguments and return validation results.
`MethodValidationResult`
`validateReturnValue(Object target, Method method, org.springframework.core.MethodParameter returnType, Object returnValue, Class<?>[] groups)`
Validate the given return value and return validation results.

## Method Details

### determineValidationGroups

Class<?>[] determineValidationGroups(Object target, Method method)
Determine the applicable validation groups. By default, obtained from an `@Validated` annotation on the method, or on the class level.

Parameters:
  `target` - the target Object
  `method` - the target method
Returns:
  the applicable validation groups as a `Class` array

### 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

### applyArgumentValidation

default void applyArgumentValidation(Object target, Method method, @Nullable org.springframework.core.MethodParameter[] parameters, Object[] arguments, Class<?>[] groups)
Delegate to `validateArguments(java.lang.Object, java.lang.reflect.Method, org.springframework.core.MethodParameter[], java.lang.Object[], java.lang.Class<?>[])` and handle the validation result, by default raising `MethodValidationException` in case of errors. Implementations may provide alternative handling, for example, injecting `Errors` into the method.

Throws:
  `MethodValidationException` - in case of unhandled errors.

### 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 validation 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)`
Returns:
  the result of validation

### applyReturnValueValidation

default void applyReturnValueValidation(Object target, Method method, @Nullable org.springframework.core.MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups)
Delegate to `validateReturnValue(java.lang.Object, java.lang.reflect.Method, org.springframework.core.MethodParameter, java.lang.Object, java.lang.Class<?>[])` and handle the validation result, by default raising `MethodValidationException` in case of errors. Implementations may provide alternative handling.

Throws:
  `MethodValidationException` - in case of unhandled errors.