All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jakarta.validation.ConstraintValidator Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
/*
 * Jakarta Bean Validation API
 *
 * License: Apache License, Version 2.0
 * See the license.txt file in the root directory or .
 */
package jakarta.validation;

import java.lang.annotation.Annotation;

import jakarta.validation.constraintvalidation.SupportedValidationTarget;

/**
 * Defines the logic to validate a given constraint {@code A}
 * for a given object type {@code T}.
 * 

* Implementations must comply to the following restriction: *

    *
  • {@code T} must resolve to a non parameterized type
  • *
  • or generic parameters of {@code T} must be unbounded * wildcard types
  • *
*

* The annotation {@link SupportedValidationTarget} can be put on a * {@code ConstraintValidator} implementation to mark it as supporting * cross-parameter constraints. Check out {@link SupportedValidationTarget} * and {@link Constraint} for more information. * * @param the annotation type handled by an implementation * @param the target type supported by an implementation * * @author Emmanuel Bernard * @author Hardy Ferentschik */ public interface ConstraintValidator { /** * Initializes the validator in preparation for * {@link #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. * * @param constraintAnnotation annotation instance for a given constraint declaration */ default void initialize(A constraintAnnotation) { } /** * Implements the validation logic. * The state of {@code value} must not be altered. *

* This method can be accessed concurrently, thread-safety must be ensured * by the implementation. * * @param value object to validate * @param context context in which the constraint is evaluated * * @return {@code false} if {@code value} does not pass the constraint */ boolean isValid(T value, ConstraintValidatorContext context); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy