Class MethodValidationAdapter
java.lang.Object
org.springframework.validation.beanvalidation.MethodValidationAdapter
- All Implemented Interfaces:
- MethodValidator
MethodValidator that uses a Bean Validation
 Validator for validation, and adapts
 ConstraintViolations to MethodValidationResult.- Since:
- 6.1
- Author:
- Rossen Stoyanchev
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceStrategy to resolve the name of an@Validmethod parameter to use for itsBindingResult.
- 
Constructor SummaryConstructorsConstructorDescriptionCreate an instance using a default JSR-303 validator underneath.MethodValidationAdapter(Validator validator) Create an instance using the given JSR-303 Validator.MethodValidationAdapter(ValidatorFactory validatorFactory) Create an instance using the given JSR-303 ValidatorFactory.MethodValidationAdapter(Supplier<Validator> validator) Create an instance for the supplied (potentially lazily initialized) Validator.
- 
Method SummaryModifier and TypeMethodDescriptionClass<?>[]determineValidationGroups(Object target, Method method) Determine the applicable validation groups.Return theconfiguredMessageCodesResolver.Return theconfiguredParameterNameDiscoverer.Return theSpringValidatorAdapterconfigured for use.final Set<ConstraintViolation<Object>> invokeValidatorForArguments(Object target, Method method, @Nullable Object[] arguments, Class<?>[] groups) Invoke the validator, and return the resulting violations.final Set<ConstraintViolation<Object>> invokeValidatorForReturnValue(Object target, Method method, @Nullable Object returnValue, Class<?>[] groups) Invoke the validator, and return the resulting violations.voidsetMessageCodesResolver(MessageCodesResolver messageCodesResolver) Set the strategy to use to determine message codes for violations.voidConfigure a resolver to determine the name of an@Validmethod parameter to use for itsBindingResult.voidsetParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDiscoverer) Set theParameterNameDiscovererto discover method parameter names with to create error codes forMessageSourceResolvable.final MethodValidationResultvalidateArguments(Object target, Method method, MethodParameter @Nullable [] parameters, @Nullable Object[] arguments, Class<?>[] groups) Validate the given method arguments and return validation results.final MethodValidationResultvalidateReturnValue(Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups) Validate the given return value and return validation results.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.validation.method.MethodValidatorapplyArgumentValidation, applyReturnValueValidation
- 
Constructor Details- 
MethodValidationAdapterpublic MethodValidationAdapter()Create an instance using a default JSR-303 validator underneath.
- 
MethodValidationAdapterCreate an instance using the given JSR-303 ValidatorFactory.- Parameters:
- validatorFactory- the JSR-303 ValidatorFactory to use
 
- 
MethodValidationAdapterCreate an instance using the given JSR-303 Validator.- Parameters:
- validator- the JSR-303 Validator to use
 
- 
MethodValidationAdapter
 
- 
- 
Method Details- 
getSpringValidatorAdapterReturn theSpringValidatorAdapterconfigured for use.
- 
setMessageCodesResolverSet the strategy to use to determine message codes for violations.Default is a DefaultMessageCodesResolver. 
- 
getMessageCodesResolverReturn theconfiguredMessageCodesResolver.
- 
setParameterNameDiscovererSet theParameterNameDiscovererto discover method parameter names with to create error codes forMessageSourceResolvable. Used only whenMethodParameters are not passed intovalidateArguments(java.lang.Object, java.lang.reflect.Method, org.springframework.core.MethodParameter[], java.lang.Object[], java.lang.Class<?>[])orvalidateReturnValue(java.lang.Object, java.lang.reflect.Method, org.springframework.core.MethodParameter, java.lang.Object, java.lang.Class<?>[]).Default is DefaultParameterNameDiscoverer.
- 
getParameterNameDiscovererReturn theconfiguredParameterNameDiscoverer.
- 
setObjectNameResolverConfigure a resolver to determine the name of an@Validmethod parameter to use for itsBindingResult. This allows aligning with a higher level programming model such as to resolve the name of an@ModelAttributemethod parameter in Spring MVC.By default, the object name is resolved through: - MethodParameter.getParameterName()for input parameters
- Conventions.getVariableNameForReturnType(Method, Class, Object)for a return type
 - "{methodName}.arg{index}"for input parameters
- "{methodName}.returnValue"for a return type
 
- 
determineValidationGroupsDetermine the applicable validation groups. By default, obtained from an@Validatedannotation on the method, or on the class level.Default are the validation groups as specified in the Validatedannotation on the method, or on the containing target class of the method, or for an AOP proxy without a target (with all behavior in advisors), also check on proxied interfaces.- Specified by:
- determineValidationGroupsin interface- MethodValidator
- Parameters:
- target- the target Object
- method- the target method
- Returns:
- the applicable validation groups as a Classarray
 
- 
validateArgumentspublic final MethodValidationResult validateArguments(Object target, Method method, MethodParameter @Nullable [] parameters, @Nullable Object[] arguments, Class<?>[] groups) Description copied from interface:MethodValidatorValidate the given method arguments and return validation results.- Specified by:
- validateArgumentsin interface- MethodValidator
- 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- MethodValidator.determineValidationGroups(java.lang.Object, java.lang.reflect.Method)
- Returns:
- the result of validation
 
- 
invokeValidatorForArguments
- 
validateReturnValuepublic final MethodValidationResult validateReturnValue(Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups) Description copied from interface:MethodValidatorValidate the given return value and return validation results.- Specified by:
- validateReturnValuein interface- MethodValidator
- 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- MethodValidator.determineValidationGroups(java.lang.Object, java.lang.reflect.Method)
- Returns:
- the result of validation
 
- 
invokeValidatorForReturnValue
 
-