类 InfraValidatorAdapter
- 所有已实现的接口:
SmartValidator,Validator,jakarta.validation.Validator
javax.validator.Validator and
exposes it as a Framework Validator
while also exposing the original JSR-303 Validator interface itself.
Can be used as a programmatic wrapper. Also serves as base class for
CustomValidatorBean and LocalValidatorFactoryBean,
and as the primary implementation of the SmartValidator interface.
this adapter is fully compatible with Bean Validation 1.1 as well as 2.0.
- 从以下版本开始:
- 4.0
- 作者:
- Juergen Hoeller, Sam Brannen
- 另请参阅:
-
构造器概要
构造器构造器说明InfraValidatorAdapter(jakarta.validation.Validator targetValidator) Create a new ContextValidatorAdapter for the given JSR-303 Validator. -
方法概要
修饰符和类型方法说明protected StringdetermineErrorCode(jakarta.validation.metadata.ConstraintDescriptor<?> descriptor) Determine a Framework-reported error code for the given constraint descriptor.protected StringdetermineField(jakarta.validation.ConstraintViolation<Object> violation) Determine a field for the given constraint violation.jakarta.validation.executable.ExecutableValidatorprotected Object[]getArgumentsForConstraint(String objectName, String field, jakarta.validation.metadata.ConstraintDescriptor<?> descriptor) Return FieldError arguments for a validation error on the given field.jakarta.validation.metadata.BeanDescriptorgetConstraintsForClass(Class<?> clazz) protected ObjectgetRejectedValue(String field, jakarta.validation.ConstraintViolation<Object> violation, BindingResult bindingResult) Extract the rejected value behind the given constraint violation, for exposure through the Framework errors representation.protected MessageSourceResolvablegetResolvableField(String objectName, String field) Build a resolvable wrapper for the specified field, allowing to resolve the field's name in aMessageSource.protected voidprocessConstraintViolations(Set<jakarta.validation.ConstraintViolation<Object>> violations, Errors errors) Process the given JSR-303 ConstraintViolations, adding corresponding errors to the provided FrameworkErrorsobject.protected booleanrequiresMessageFormat(jakarta.validation.ConstraintViolation<?> violation) Indicate whether this violation's interpolated message has remaining placeholders and therefore requiresMessageFormatto be applied to it.boolean<T> TvoidValidate the suppliedtargetobject, which must be of aClassfor which theValidator.supports(Class)method typically has (or would) returntrue.voidValidate the suppliedtargetobject, which must be of a type ofClassfor which theValidator.supports(Class)method typically returnstrue.<T> Set<jakarta.validation.ConstraintViolation<T>><T> Set<jakarta.validation.ConstraintViolation<T>>validateProperty(T object, String propertyName, Class<?>... groups) voidvalidateValue(Class<?> targetType, String fieldName, Object value, Errors errors, Object... validationHints) Validate the supplied value for the specified field on the target type, reporting the same validation errors as if the value would be bound to the field on an instance of the target class.<T> Set<jakarta.validation.ConstraintViolation<T>>validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups)
-
构造器详细资料
-
InfraValidatorAdapter
public InfraValidatorAdapter(jakarta.validation.Validator targetValidator) Create a new ContextValidatorAdapter for the given JSR-303 Validator.- 参数:
targetValidator- the JSR-303 Validator to wrap
-
-
方法详细资料
-
supports
从接口复制的说明:Validator -
validate
从接口复制的说明:ValidatorValidate the suppliedtargetobject, which must be of aClassfor which theValidator.supports(Class)method typically has (or would) returntrue.The supplied
errorsinstance can be used to report any resulting validation errors. -
validate
从接口复制的说明:SmartValidatorValidate the suppliedtargetobject, which must be of a type ofClassfor which theValidator.supports(Class)method typically returnstrue.The supplied
errorsinstance can be used to report any resulting validation errors.This variant of
validate()supports validation hints, such as validation groups against a JSR-303 provider (in which case, the provided hint objects need to be annotation arguments of typeClass).Note: Validation hints may get ignored by the actual target
Validator, in which case this method should behave just like its regularValidator.validate(Object, Errors)sibling.- 指定者:
validate在接口中SmartValidator- 参数:
target- the object that is to be validatederrors- contextual state about the validation processvalidationHints- one or more hint objects to be passed to the validation engine- 另请参阅:
-
Validator.validate(Object, Class[])
-
validateValue
public void validateValue(Class<?> targetType, String fieldName, @Nullable Object value, Errors errors, Object... validationHints) 从接口复制的说明:SmartValidatorValidate the supplied value for the specified field on the target type, reporting the same validation errors as if the value would be bound to the field on an instance of the target class.- 指定者:
validateValue在接口中SmartValidator- 参数:
targetType- the target typefieldName- the name of the fieldvalue- the candidate valueerrors- contextual state about the validation processvalidationHints- one or more hint objects to be passed to the validation engine- 另请参阅:
-
Validator.validateValue(Class, String, Object, Class[])
-
processConstraintViolations
protected void processConstraintViolations(Set<jakarta.validation.ConstraintViolation<Object>> violations, Errors errors) Process the given JSR-303 ConstraintViolations, adding corresponding errors to the provided FrameworkErrorsobject.- 参数:
violations- the JSR-303 ConstraintViolation resultserrors- the Framework errors object to register to
-
determineField
Determine a field for the given constraint violation.The default implementation returns the stringified property path.
- 参数:
violation- the current JSR-303 ConstraintViolation- 返回:
- the Framework-reported field (for use with
Errors) - 另请参阅:
-
ConstraintViolation.getPropertyPath()FieldError.getField()
-
determineErrorCode
Determine a Framework-reported error code for the given constraint descriptor.The default implementation returns the simple class name of the descriptor's annotation type. Note that the configured
MessageCodesResolverwill automatically generate error code variations which include the object name and the field name.- 参数:
descriptor- the JSR-303 ConstraintDescriptor for the current violation- 返回:
- a corresponding error code (for use with
Errors) - 另请参阅:
-
ConstraintDescriptor.getAnnotation()MessageCodesResolver
-
getArgumentsForConstraint
protected Object[] getArgumentsForConstraint(String objectName, String field, jakarta.validation.metadata.ConstraintDescriptor<?> descriptor) Return FieldError arguments for a validation error on the given field. Invoked for each violated constraint.The default implementation returns a first argument indicating the field name (see
getResolvableField(java.lang.String, java.lang.String)). Afterwards, it adds all actual constraint annotation attributes (i.e. excluding "message", "groups" and "payload") in alphabetical order of their attribute names.Can be overridden to e.g. add further attributes from the constraint descriptor.
- 参数:
objectName- the name of the target objectfield- the field that caused the binding errordescriptor- the JSR-303 constraint descriptor- 返回:
- the Object array that represents the FieldError arguments
- 另请参阅:
-
getResolvableField
Build a resolvable wrapper for the specified field, allowing to resolve the field's name in aMessageSource.The default implementation returns a first argument indicating the field: of type
DefaultMessageSourceResolvable, with "objectName.field" and "field" as codes, and with the plain field name as default message.- 参数:
objectName- the name of the target objectfield- the field that caused the binding error- 返回:
- a corresponding
MessageSourceResolvablefor the specified field - 另请参阅:
-
getRejectedValue
@Nullable protected Object getRejectedValue(String field, jakarta.validation.ConstraintViolation<Object> violation, BindingResult bindingResult) Extract the rejected value behind the given constraint violation, for exposure through the Framework errors representation.- 参数:
field- the field that caused the binding errorviolation- the corresponding JSR-303 ConstraintViolationbindingResult- a Framework BindingResult for the backing object which contains the current field's value- 返回:
- the invalid value to expose as part of the field error
- 另请参阅:
-
ConstraintViolation.getInvalidValue()FieldError.getRejectedValue()
-
requiresMessageFormat
protected boolean requiresMessageFormat(jakarta.validation.ConstraintViolation<?> violation) Indicate whether this violation's interpolated message has remaining placeholders and therefore requiresMessageFormatto be applied to it. Called for a Bean Validation defined message (coming outValidationMessages.properties) when rendered as the default message in Framework's MessageSource.The default implementation considers a Framework-style "{0}" placeholder for the field name as an indication for
MessageFormat. Any other placeholder or escape syntax occurrences are typically a mismatch, coming out of regex pattern values or the like. Note that standard Bean Validation does not support "{0}" style placeholders at all; this is a feature typically used in Framework MessageSource resource bundles.- 参数:
violation- the Bean Validation constraint violation, including BV-defined interpolation of named attribute references in its message- 返回:
trueifjava.text.MessageFormatis to be applied, orfalseif the violation's message should be used as-is- 另请参阅:
-
validate
- 指定者:
validate在接口中jakarta.validation.Validator
-
validateProperty
public <T> Set<jakarta.validation.ConstraintViolation<T>> validateProperty(T object, String propertyName, Class<?>... groups) - 指定者:
validateProperty在接口中jakarta.validation.Validator
-
validateValue
public <T> Set<jakarta.validation.ConstraintViolation<T>> validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups) - 指定者:
validateValue在接口中jakarta.validation.Validator
-
getConstraintsForClass
- 指定者:
getConstraintsForClass在接口中jakarta.validation.Validator
-
unwrap
- 指定者:
unwrap在接口中jakarta.validation.Validator
-
forExecutables
public jakarta.validation.executable.ExecutableValidator forExecutables()- 指定者:
forExecutables在接口中jakarta.validation.Validator
-