javax.validator.Validator and
exposes it as a Spring org.springframework.validation.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.
As of Spring Framework 5.0, this adapter is fully compatible with Bean Validation 1.1 as well as 2.0.
SmartValidator, CustomValidatorBean, LocalValidatorFactoryBean
| Modifier and Type | Class and Description |
|---|---|
| private static class | SpringValidatorAdapter.
Wrapper for a String attribute which can be resolved via a |
| private static class | SpringValidatorAdapter.
Subclass of |
| private static class | SpringValidatorAdapter.
Subclass of |
| Modifier and Type | Field and Description |
|---|---|
| private static final Set | |
| private Validator |
| Access | Constructor and Description |
|---|---|
| public | SpringValidatorAdapter(Validator
the JSR-303 Validator to wrap targetValidator)Create a new SpringValidatorAdapter for the given JSR-303 Validator. |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| private Class | asValidationGroups(Object... validationHints)
Turn the specified validation hints into JSR-303 validation groups. |
| private static boolean | |
| protected String | Returns: a corresponding error code (for use withErrors)the JSR-303 ConstraintDescriptor for the current violation descriptor)Determine a Spring-reported error code for the given constraint descriptor. |
| protected String | Returns: the Spring-reported field (for use withErrors)the current JSR-303 ConstraintViolation violation)Determine a field for the given constraint violation. |
| public ExecutableValidator | forExecutables()
Implements jakarta. Returns the contract for validating parameters and return values of methods and constructors. |
| protected Object[] | Returns: the Object array that represents the FieldError argumentsthe name of the target object objectName, String the field that caused the binding error field, ConstraintDescriptor<?> the JSR-303 constraint descriptor descriptor)Return FieldError arguments for a validation error on the given field. |
| public BeanDescriptor | getConstraintsForClass(Class<?>
class or interface type evaluated clazz)Implements jakarta. Returns the descriptor object describing bean constraints. |
| protected Object | Returns: the invalid value to expose as part of the field errorthe field that caused the binding error field, ConstraintViolation<Object> the corresponding JSR-303 ConstraintViolation violation, BindingResult a Spring BindingResult for the backing object
which contains the current field's value bindingResult)Extract the rejected value behind the given constraint violation, for exposure through the Spring errors representation. |
| protected MessageSourceResolvable | Returns: a correspondingMessageSourceResolvable for the specified fieldthe name of the target object objectName, String the field that caused the binding error field)Build a resolvable wrapper for the specified field, allowing to resolve the field's
name in a |
| protected void | processConstraintViolations(Set<ConstraintViolation<Object>>
the JSR-303 ConstraintViolation results violations, Errors the Spring errors object to register to errors)Process the given JSR-303 ConstraintViolations, adding corresponding errors to
the provided Spring |
| protected boolean | Returns: true if java.text.MessageFormat is to be applied,
or false if the violation's message should be used as-isthe Bean Validation constraint violation, including
BV-defined interpolation of named attribute references in its message violation)Indicate whether this violation's interpolated message has remaining
placeholders and therefore requires |
| pack-priv void | |
| public boolean | |
| public <T> T | unwrap(Class<T>
the class of the object to return type)Overrides default org. Implements jakarta. Return a contained validator instance of the specified type, unwrapping as far as necessary. |
| public void | validate(Object
the object that is to be validated target, Errors contextual state about the validation process errors)Implements org. Validate the given |
| public void | validate(Object
the object that is to be validated target, Errors contextual state about the validation process errors, Object... one or more hint objects to be passed to the validation engine validationHints)Implements org. Validate the supplied |
| public <T> Set | validate(T
object to validate object, Class<?>... the group or list of groups targeted for validation (defaults to
groups)Default)Implements jakarta. Validates all constraints on |
| public <T> Set | validateProperty(T
object to validate object, String property to validate (i.e. field and getter constraints) propertyName, Class<?>... the group or list of groups targeted for validation (defaults to
groups)Default)Implements jakarta. Validates all constraints placed on the property of |
| public void | validateValue(Class<?>
the target type targetType, String the name of the field fieldName, Object the candidate value value, Errors contextual state about the validation process errors, Object... one or more hint objects to be passed to the validation engine validationHints)Overrides default org. 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. |
| public <T> Set | validateValue(Class<T>
the bean type beanType, String property to validate propertyName, Object property value to validate value, Class<?>... the group or list of groups targeted for validation (defaults to
groups)Default).Implements jakarta. Validates all constraints placed on the property named |
| internalAnnotationAttributes | back to summary |
|---|---|
| private static final Set<String> internalAnnotationAttributes | |
| targetValidator | back to summary |
|---|---|
| private Validator targetValidator
| |
| SpringValidatorAdapter | back to summary |
|---|---|
| public SpringValidatorAdapter(Validator targetValidator) Create a new SpringValidatorAdapter for the given JSR-303 Validator.
| |
| SpringValidatorAdapter | back to summary |
|---|---|
| pack-priv SpringValidatorAdapter() | |
| asValidationGroups | back to summary |
|---|---|
| private Class Turn the specified validation hints into JSR-303 validation groups.
| |
| containsSpringStylePlaceholder | back to summary |
|---|---|
| private static boolean containsSpringStylePlaceholder(String message) | |
| determineErrorCode | back to summary |
|---|---|
| protected String determineErrorCode(ConstraintDescriptor<?> descriptor) Determine a Spring-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
| |
| determineField | back to summary |
|---|---|
| protected String determineField(ConstraintViolation<Object> violation) Determine a field for the given constraint violation. The default implementation returns the stringified property path.
| |
| forExecutables | back to summary |
|---|---|
| public ExecutableValidator forExecutables() Implements jakarta. Doc from jakarta. Returns the contract for validating parameters and return values of methods and constructors.
| |
| getArgumentsForConstraint | back to summary |
|---|---|
| protected Object[] getArgumentsForConstraint(String objectName, String field, 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 Can be overridden to e.g. add further attributes from the constraint descriptor.
| |
| getConstraintsForClass | back to summary |
|---|---|
| public BeanDescriptor getConstraintsForClass(Class<?> clazz) Implements jakarta. Doc from jakarta. Returns the descriptor object describing bean constraints.
The returned object (and associated objects including
| |
| getRejectedValue | back to summary |
|---|---|
| protected Object getRejectedValue(String field, ConstraintViolation<Object> violation, BindingResult bindingResult) Extract the rejected value behind the given constraint violation, for exposure through the Spring errors representation.
| |
| getResolvableField | back to summary |
|---|---|
| protected MessageSourceResolvable getResolvableField(String objectName, String field) Build a resolvable wrapper for the specified field, allowing to resolve the field's
name in a The default implementation returns a first argument indicating the field:
of type
| |
| processConstraintViolations | back to summary |
|---|---|
| protected void processConstraintViolations(Set<ConstraintViolation<Object>> violations, Errors errors) Process the given JSR-303 ConstraintViolations, adding corresponding errors to
the provided Spring
| |
| requiresMessageFormat | back to summary |
|---|---|
| protected boolean requiresMessageFormat(ConstraintViolation<?> violation) Indicate whether this violation's interpolated message has remaining
placeholders and therefore requires The default implementation considers a Spring-style "{0}" placeholder
for the field name as an indication for
| |
| setTargetValidator | back to summary |
|---|---|
| pack-priv void setTargetValidator(Validator targetValidator) | |
| supports | back to summary |
|---|---|
| public boolean supports(Class<?> clazz) Implements org. Doc from org. Can this This method is typically implemented like so: return Foo.class.isAssignableFrom(clazz);(Where Foo is the class (or superclass) of the actual
object instance that is to be validated.)
| |
| unwrap | back to summary |
|---|---|
| public <T> T unwrap(Class<T> type) Overrides default org. Implements jakarta. Doc from org. Return a contained validator instance of the specified type, unwrapping as far as necessary.
| |
| validate | back to summary |
|---|---|
| public void validate(Object target, Errors errors) Implements org. Doc from org. Validate the given The supplied | |
| validate | back to summary |
|---|---|
| public void validate(Object target, Errors errors, Object... validationHints) Implements org. Doc from org. Validate the supplied The supplied This variant of Note Validation hints may get ignored by the actual target | |
| validate | back to summary |
|---|---|
| public <T> Set Implements jakarta. Doc from jakarta. Validates all constraints on
| |
| validateProperty | back to summary |
|---|---|
| public <T> Set Implements jakarta. Doc from jakarta. Validates all constraints placed on the property of
| |
| validateValue | back to summary |
|---|---|
| public void validateValue(Class<?> targetType, String fieldName, Object value, Errors errors, Object... validationHints) Overrides default org. Doc from org. 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.
| |
| validateValue | back to summary |
|---|---|
| public <T> Set Implements jakarta. Doc from jakarta. Validates all constraints placed on the property named
| |
MessageSource,
falling back to the original attribute as a default value otherwise.
| Modifier and Type | Field and Description |
|---|---|
| private final String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Object[] | getArguments()
Overrides default org. Return the array of arguments to be used to resolve this message. |
| public String[] | getCodes()
Implements org. Return the codes to be used to resolve this message, in the order that they should get tried. |
| public String | getDefaultMessage()
Overrides default org. Return the default message to be used to resolve this message. |
| public String |
| resolvableString | back to summary |
|---|---|
| private final String resolvableString | |
| ResolvableAttribute | back to summary |
|---|---|
| public ResolvableAttribute(String resolvableString) | |
| getArguments | back to summary |
|---|---|
| public Object[] getArguments() Overrides default org. Doc from org. Return the array of arguments to be used to resolve this message. The default implementation simply returns | |
| getCodes | back to summary |
|---|---|
| public String[] getCodes() Implements org. Doc from org. Return the codes to be used to resolve this message, in the order that they should get tried. The last code will therefore be the default one. | |
| getDefaultMessage | back to summary |
|---|---|
| public String getDefaultMessage() Overrides default org. Doc from org. Return the default message to be used to resolve this message. The default implementation simply returns | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
FieldError with Spring-style default message rendering.
| Modifier and Type | Field and Description |
|---|---|
| private transient SpringValidatorAdapter | |
| private transient ConstraintViolation |
| Access | Constructor and Description |
|---|---|
| public | ViolationFieldError(String objectName, String field, Object rejectedValue, String[] codes, Object[] arguments, ConstraintViolation<?> violation, SpringValidatorAdapter adapter)
|
| Modifier and Type | Method and Description |
|---|---|
| public boolean | shouldRenderDefaultMessage()
Overrides org. Indicate whether the specified default message needs to be rendered for
substituting placeholders and/or |
| adapter | back to summary |
|---|---|
| private transient SpringValidatorAdapter adapter
| |
| violation | back to summary |
|---|---|
| private transient ConstraintViolation<?> violation
| |
| ViolationFieldError | back to summary |
|---|---|
| public ViolationFieldError(String objectName, String field, Object rejectedValue, String[] codes, Object[] arguments, ConstraintViolation<?> violation, SpringValidatorAdapter adapter) | |
| shouldRenderDefaultMessage | back to summary |
|---|---|
| public boolean shouldRenderDefaultMessage() Overrides org. Doc from org. Indicate whether the specified default message needs to be rendered for
substituting placeholders and/or
| |
ObjectError with Spring-style default message rendering.
| Modifier and Type | Field and Description |
|---|---|
| private transient SpringValidatorAdapter | |
| private transient ConstraintViolation |
| Access | Constructor and Description |
|---|---|
| public | ViolationObjectError(String objectName, String[] codes, Object[] arguments, ConstraintViolation<?> violation, SpringValidatorAdapter adapter)
|
| Modifier and Type | Method and Description |
|---|---|
| public boolean | shouldRenderDefaultMessage()
Overrides org. Indicate whether the specified default message needs to be rendered for
substituting placeholders and/or |
| adapter | back to summary |
|---|---|
| private transient SpringValidatorAdapter adapter
| |
| violation | back to summary |
|---|---|
| private transient ConstraintViolation<?> violation
| |
| ViolationObjectError | back to summary |
|---|---|
| public ViolationObjectError(String objectName, String[] codes, Object[] arguments, ConstraintViolation<?> violation, SpringValidatorAdapter adapter) | |
| shouldRenderDefaultMessage | back to summary |
|---|---|
| public boolean shouldRenderDefaultMessage() Overrides org. Doc from org. Indicate whether the specified default message needs to be rendered for
substituting placeholders and/or
| |