Top Description Methods
javax.validation

public Interface Validator

Imports
java.util.Set, javax.validation.executable.ExecutableValidator, javax.validation.groups.Default, javax.validation.metadata.BeanDescriptor, .ConstraintDescriptor

Validates bean instances. Implementations of this interface must be thread-safe.
Authors
Emmanuel Bernard, Hardy Ferentschik, Gunnar Morling

Method Summary

Modifier and TypeMethod and Description
public ExecutableValidator

Returns:

contract for method and constructor validation
forExecutables
()

Returns the contract for validating parameters and return values of methods and constructors.

public BeanDescriptor

Returns:

the bean descriptor for the specified class
getConstraintsForClass
(Class<?>
class or interface type evaluated
clazz
)

Returns the descriptor object describing bean constraints.

public <
the type of the object to be returned
T
>
T

Returns:

an instance of the specified class
unwrap
(Class<T>
the class of the object to be returned
type
)

Returns an instance of the specified type allowing access to provider-specific APIs.

public <
the type of the object to validate
T
>
Set<ConstraintViolation<T>>

Returns:

constraint violations or an empty set if none
validate
(T
object to validate
object
,
Class<?>...
the group or list of groups targeted for validation (defaults to Default)
groups
)

Validates all constraints on object.

public <
the type of the object to validate
T
>
Set<ConstraintViolation<T>>

Returns:

constraint violations or an empty set if none
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 Default)
groups
)

Validates all constraints placed on the property of object named propertyName.

public <
the type of the object to validate
T
>
Set<ConstraintViolation<T>>

Returns:

constraint violations or an empty set if none
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 Default).
groups
)

Validates all constraints placed on the property named propertyName of the class beanType would the property value be value.

Method Detail

forExecutablesback to summary
public ExecutableValidator forExecutables()

Returns the contract for validating parameters and return values of methods and constructors.

Returns:ExecutableValidator

contract for method and constructor validation

Since
1.1
getConstraintsForClassback to summary
public BeanDescriptor getConstraintsForClass(Class<?> clazz)

Returns the descriptor object describing bean constraints.

The returned object (and associated objects including ConstraintDescriptors) are immutable.

Parameters
clazz:Class<?>

class or interface type evaluated

Returns:BeanDescriptor

the bean descriptor for the specified class

Exceptions
IllegalArgumentException:
if clazz is null
ValidationException:
if a non recoverable error happens during the metadata discovery or if some constraints are invalid.
unwrapback to summary
public <T> T unwrap(Class<T> type)

Returns an instance of the specified type allowing access to provider-specific APIs.

If the Bean Validation provider implementation does not support the specified class, ValidationException is thrown.

Parameters
<T>
the type of the object to be returned
type:Class<T>

the class of the object to be returned

Returns:T

an instance of the specified class

Exceptions
ValidationException:
if the provider does not support the call
validateback to summary
public <T> Set<ConstraintViolation<T>> validate(T object, Class<?>... groups)

Validates all constraints on object.

Parameters
<T>
the type of the object to validate
object:T

object to validate

groups:Class<?>[]

the group or list of groups targeted for validation (defaults to Default)

Returns:Set<ConstraintViolation<T>>

constraint violations or an empty set if none

Exceptions
IllegalArgumentException:
if object is null or if null is passed to the varargs groups
ValidationException:
if a non recoverable error happens during the validation process
validatePropertyback to summary
public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyName, Class<?>... groups)

Validates all constraints placed on the property of object named propertyName.

Parameters
<T>
the type of the object to validate
object:T

object to validate

propertyName:String

property to validate (i.e. field and getter constraints)

groups:Class<?>[]

the group or list of groups targeted for validation (defaults to Default)

Returns:Set<ConstraintViolation<T>>

constraint violations or an empty set if none

Exceptions
IllegalArgumentException:
if object is null, if propertyName is null, empty or not a valid object property or if null is passed to the varargs groups
ValidationException:
if a non recoverable error happens during the validation process
validateValueback to summary
public <T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups)

Validates all constraints placed on the property named propertyName of the class beanType would the property value be value.

ConstraintViolation objects return null for ConstraintViolation#getRootBean() and ConstraintViolation#getLeafBean().

Parameters
<T>
the type of the object to validate
beanType:Class<T>

the bean type

propertyName:String

property to validate

value:Object

property value to validate

groups:Class<?>[]

the group or list of groups targeted for validation (defaults to Default).

Returns:Set<ConstraintViolation<T>>

constraint violations or an empty set if none

Exceptions
IllegalArgumentException:
if beanType is null, if propertyName is null, empty or not a valid object property or if null is passed to the varargs groups
ValidationException:
if a non recoverable error happens during the validation process