Top Description Inners Fields Constructors Methods
org.springframework.web.method.annotation

public final Class HandlerMethodValidator

extends Object
implements MethodValidator
Class Inheritance
All Implemented Interfaces
org.springframework.validation.method.MethodValidator
Imports
java.lang.reflect.Method, java.util.function.Predicate, jakarta.validation.Validator, org.springframework.core.Conventions, .MethodParameter, .ParameterNameDiscoverer, org.springframework.lang.Nullable, org.springframework.validation.BindingResult, .MessageCodesResolver, .SmartValidator, org.springframework.validation.beanvalidation.MethodValidationAdapter, org.springframework.validation.method.MethodValidationResult, .MethodValidator, .ParameterErrors, org.springframework.web.bind.annotation.RequestBody, .RequestPart, org.springframework.web.bind.support.ConfigurableWebBindingInitializer, .WebBindingInitializer

MethodValidator that uses Bean Validation to validate @RequestMapping method arguments.

Handles validation results by populating BindingResult method arguments with errors from beanResults. Also, helps to determine parameter names for @ModelAttribute and @RequestBody parameters.

Author
Rossen Stoyanchev
Since
6.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
HandlerMethodValidator.WebObjectNameResolver

ObjectNameResolver for web controller methods.

Field Summary

Modifier and TypeField and Description
private final Predicate<MethodParameter>
private static final MethodValidationAdapter.ObjectNameResolver
private final Predicate<MethodParameter>
private final MethodValidationAdapter

Constructor Summary

AccessConstructor and Description
private
HandlerMethodValidator(MethodValidationAdapter validationAdapter, Predicate<MethodParameter> modelAttributePredicate, Predicate<MethodParameter> requestParamPredicate)

Method Summary

Modifier and TypeMethod and Description
public void
applyArgumentValidation(Object target, Method method, MethodParameter[] parameters, Object[] arguments, Class<?>[] groups)

Overrides default org.springframework.validation.method.MethodValidator.applyArgumentValidation.

Delegate to validateArguments and handle the validation result, by default raising MethodValidationException in case of errors.

public void
applyReturnValueValidation(Object target, Method method, MethodParameter returnType, Object returnValue, Class<?>[] groups)

Overrides default org.springframework.validation.method.MethodValidator.applyReturnValueValidation.

Delegate to validateReturnValue and handle the validation result, by default raising MethodValidationException in case of errors.

public Class<?>[]
determineValidationGroups(Object
the target Object
target
,
Method
the target method
method
)

Implements org.springframework.validation.method.MethodValidator.determineValidationGroups.

Determine the applicable validation groups.

public static MethodValidator
from(WebBindingInitializer initializer, ParameterNameDiscoverer paramNameDiscoverer, Predicate<MethodParameter> modelAttributePredicate, Predicate<MethodParameter> requestParamPredicate)

Static factory method to create a HandlerMethodValidator when Bean Validation is enabled for use via ConfigurableWebBindingInitializer, for example in Spring MVC or WebFlux config.

private static Validator
public MethodValidationResult
validateArguments(Object
the target Object
target
,
Method
the target method
method
,
MethodParameter[]
the parameters, if already created and available
parameters
,
Object[]
the candidate argument values to validate
arguments
,
Class<?>[]
validation groups from determineValidationGroups
groups
)

Implements org.springframework.validation.method.MethodValidator.validateArguments.

Validate the given method arguments and return validation results.

public MethodValidationResult
validateReturnValue(Object
the target Object
target
,
Method
the target method
method
,
MethodParameter
the return parameter, if already created and available
returnType
,
Object
the return value to validate
returnValue
,
Class<?>[]
validation groups from determineValidationGroups
groups
)

Implements org.springframework.validation.method.MethodValidator.validateReturnValue.

Validate the given return value and return validation results.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

modelAttributePredicateback to summary
private final Predicate<MethodParameter> modelAttributePredicate
objectNameResolverback to summary
private static final MethodValidationAdapter.ObjectNameResolver objectNameResolver
requestParamPredicateback to summary
private final Predicate<MethodParameter> requestParamPredicate
validationAdapterback to summary
private final MethodValidationAdapter validationAdapter

Constructor Detail

HandlerMethodValidatorback to summary
private HandlerMethodValidator(MethodValidationAdapter validationAdapter, Predicate<MethodParameter> modelAttributePredicate, Predicate<MethodParameter> requestParamPredicate)

Method Detail

applyArgumentValidationback to summary
public void applyArgumentValidation(Object target, Method method, MethodParameter[] parameters, Object[] arguments, Class<?>[] groups)

Overrides default org.springframework.validation.method.MethodValidator.applyArgumentValidation.

Doc from org.springframework.validation.method.MethodValidator.applyArgumentValidation.

Delegate to validateArguments and handle the validation result, by default raising MethodValidationException in case of errors. Implementations may provide alternative handling, e.g. injecting org.springframework.validation.Errors into the method.

Annotations
@Override
applyReturnValueValidationback to summary
public void applyReturnValueValidation(Object target, Method method, MethodParameter returnType, Object returnValue, Class<?>[] groups)

Overrides default org.springframework.validation.method.MethodValidator.applyReturnValueValidation.

Doc from org.springframework.validation.method.MethodValidator.applyReturnValueValidation.

Delegate to validateReturnValue and handle the validation result, by default raising MethodValidationException in case of errors. Implementations may provide alternative handling.

Annotations
@Override
determineValidationGroupsback to summary
public Class<?>[] determineValidationGroups(Object target, Method method)

Implements org.springframework.validation.method.MethodValidator.determineValidationGroups.

Doc from org.springframework.validation.method.MethodValidator.determineValidationGroups.

Determine the applicable validation groups. By default, obtained from an @Validated annotation on the method, or on the class level.

Parameters
target:Object

the target Object

method:Method

the target method

Returns:Class<?>[]

the applicable validation groups as a Class array

Annotations
@Override
fromback to summary
public static MethodValidator from(WebBindingInitializer initializer, ParameterNameDiscoverer paramNameDiscoverer, Predicate<MethodParameter> modelAttributePredicate, Predicate<MethodParameter> requestParamPredicate)

Static factory method to create a HandlerMethodValidator when Bean Validation is enabled for use via ConfigurableWebBindingInitializer, for example in Spring MVC or WebFlux config.

Annotations
@Nullable
getValidatorback to summary
private static Validator getValidator(ConfigurableWebBindingInitializer initializer)
Annotations
@Nullable
validateArgumentsback to summary
public MethodValidationResult validateArguments(Object target, Method method, MethodParameter[] parameters, Object[] arguments, Class<?>[] groups)

Implements org.springframework.validation.method.MethodValidator.validateArguments.

Doc from org.springframework.validation.method.MethodValidator.validateArguments.

Validate the given method arguments and return validation results.

Parameters
target:Object

the target Object

method:Method

the target method

parameters:MethodParameter[]

the parameters, if already created and available

arguments:Object[]

the candidate argument values to validate

groups:Class<?>[]

validation groups from determineValidationGroups

Returns:MethodValidationResult

the result of validation

Annotations
@Override
validateReturnValueback to summary
public MethodValidationResult validateReturnValue(Object target, Method method, MethodParameter returnType, Object returnValue, Class<?>[] groups)

Implements org.springframework.validation.method.MethodValidator.validateReturnValue.

Doc from org.springframework.validation.method.MethodValidator.validateReturnValue.

Validate the given return value and return validation results.

Parameters
target:Object

the target Object

method:Method

the target method

returnType:MethodParameter

the return parameter, if already created and available

returnValue:Object

the return value to validate

groups:Class<?>[]

validation groups from determineValidationGroups

Returns:MethodValidationResult

the result of validation

Annotations
@Override
org.springframework.web.method.annotation back to summary

private Class HandlerMethodValidator.WebObjectNameResolver

extends Object
implements ObjectNameResolver
Class Inheritance
  • java.lang.Object
  • org.springframework.web.method.annotation.HandlerMethodValidator.WebObjectNameResolver
All Implemented Interfaces
org.springframework.validation.beanvalidation.MethodValidationAdapter.ObjectNameResolver

ObjectNameResolver for web controller methods.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String
resolveName(MethodParameter
the method parameter
param
,
Object
the argument value or return value
value
)

Implements org.springframework.validation.beanvalidation.MethodValidationAdapter.ObjectNameResolver.resolveName.

Determine the name for the given method argument.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

WebObjectNameResolverback to summary
private WebObjectNameResolver()

Method Detail

resolveNameback to summary
public String resolveName(MethodParameter param, Object value)

Implements org.springframework.validation.beanvalidation.MethodValidationAdapter.ObjectNameResolver.resolveName.

Doc from org.springframework.validation.beanvalidation.MethodValidationAdapter.ObjectNameResolver.resolveName.

Determine the name for the given method argument.

Parameters
param:MethodParameter

the method parameter

value:Object

the argument value or return value

Returns:String

the name to use

Annotations
@Override