Top Description Methods
jakarta.validation

public Interface ConstraintValidator<A extends Annotation, T>

Type Parameters
<A>
the annotation type handled by an implementation
<T>
the target type supported by an implementation
Imports
java.lang.annotation.Annotation, jakarta.validation.constraintvalidation.SupportedValidationTarget

Defines the logic to validate a given constraint A for a given object type T.

Implementations must comply to the following restriction:

The annotation SupportedValidationTarget can be put on a ConstraintValidator implementation to mark it as supporting cross-parameter constraints. Check out SupportedValidationTarget and Constraint for more information.

Authors
Emmanuel Bernard, Hardy Ferentschik

Method Summary

Modifier and TypeMethod and Description
public default void
initialize(A
annotation instance for a given constraint declaration
constraintAnnotation
)

Initializes the validator in preparation for isValid(Object, ConstraintValidatorContext) calls.

public boolean

Returns:

false if value does not pass the constraint
isValid
(T
object to validate
value
,
ConstraintValidatorContext
context in which the constraint is evaluated
context
)

Implements the validation logic.

Method Detail

initializeback to summary
public default void initialize(A constraintAnnotation)

Initializes the validator in preparation for isValid(Object, ConstraintValidatorContext) calls. The constraint annotation for a given constraint declaration is passed.

This method is guaranteed to be called before any use of this instance for validation.

The default implementation is a no-op.

Parameters
constraintAnnotation:A

annotation instance for a given constraint declaration

isValidback to summary
public boolean isValid(T value, ConstraintValidatorContext context)

Implements the validation logic. The state of value must not be altered.

This method can be accessed concurrently, thread-safety must be ensured by the implementation.

Parameters
value:T

object to validate

context:ConstraintValidatorContext

context in which the constraint is evaluated

Returns:boolean

false if value does not pass the constraint