public class

SpringValidatorAdapter

extends Object
implements Validator
java.lang.Object
   ↳ org.springframework.validation.beanvalidation.SpringValidatorAdapter
Known Direct Subclasses

Class Overview

Adapter that takes a JSR-303 javax.validator.Validator and exposes it as a Spring 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.

Summary

Public Constructors
SpringValidatorAdapter(javax.validation.Validator targetValidator)
Create a new SpringValidatorAdapter for the given JSR-303 Validator.
Public Methods
BeanDescriptor getConstraintsForClass(Class<?> clazz)
boolean supports(Class<?> clazz)
Can this Validator validate instances of the supplied clazz?

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.)
<T> T unwrap(Class<T> type)
void validate(Object target, Errors errors)
Validate the supplied target object, which must be of a Class for which the supports(Class) method typically has (or would) return true.
<T> Set<> validate(T object, Class...<?> groups)
<T> Set<> validateProperty(T object, String propertyName, Class...<?> groups)
<T> Set<> validateValue(Class<T> beanType, String propertyName, Object value, Class...<?> groups)
Protected Methods
Object[] getArgumentsForConstraint(String objectName, String field, descriptor)
Return FieldError arguments for a validation error on the given field.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.validation.Validator

Public Constructors

public SpringValidatorAdapter (javax.validation.Validator targetValidator)

Create a new SpringValidatorAdapter for the given JSR-303 Validator.

Parameters
targetValidator the JSR-303 Validator to wrap

Public Methods

public BeanDescriptor getConstraintsForClass (Class<?> clazz)

public boolean supports (Class<?> clazz)

Can this Validator validate instances of the supplied clazz?

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.)

Parameters
clazz the Class that this Validator is being asked if it can validate
Returns

public T unwrap (Class<T> type)

public void validate (Object target, Errors errors)

Validate the supplied target object, which must be of a Class for which the supports(Class) method typically has (or would) return true.

The supplied errors instance can be used to report any resulting validation errors.

Parameters
target the object that is to be validated (can be null)
errors contextual state about the validation process (never null)

public Set<> validate (T object, Class...<?> groups)

public Set<> validateProperty (T object, String propertyName, Class...<?> groups)

public Set<> validateValue (Class<T> beanType, String propertyName, Object value, Class...<?> groups)

Protected Methods

protected Object[] getArgumentsForConstraint (String objectName, String field, 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 (of type DefaultMessageSourceResolvable, with "objectName.field" and "field" as codes). 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.

Parameters
objectName the name of the target object
field the field that caused the binding error
descriptor the JSR-303 constraint descriptor
Returns
  • the Object array that represents the FieldError arguments