Interface ConstraintValidator<A extends java.lang.annotation.Annotation,​T>

  • Type Parameters:
    A - The annotation type
    T - The supported validation types
    All Superinterfaces:
    javax.validation.ConstraintValidator<A,​T>
    All Known Subinterfaces:
    DecimalMaxValidator<T>, DecimalMinValidator<T>, DigitsValidator<T>, SizeValidator<T>
    All Known Implementing Classes:
    EmailValidator, PatternValidator
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @Indexed(ConstraintValidator.class)
    @FunctionalInterface
    public interface ConstraintValidator<A extends java.lang.annotation.Annotation,​T>
    extends javax.validation.ConstraintValidator<A,​T>
    Constraint validator that can be used at either runtime or compilation time and is capable of validation Constraint instances. Allows defining validators that work with both Hibernate validator and Micronaut's validator.

    Unlike the specification's interface this one can uses as a functional interface. Implementor should not implement the ConstraintValidator.initialize(Annotation) method and should instead read the passed AnnotationValue.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static ConstraintValidator VALID
      A constraint validator that just returns the object as being valid.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      boolean isValid​(T value, io.micronaut.core.annotation.AnnotationValue<A> annotationMetadata, ConstraintValidatorContext context)
      Implements the validation logic.
      default boolean isValid​(T value, javax.validation.ConstraintValidatorContext context)  
      • Methods inherited from interface javax.validation.ConstraintValidator

        initialize
    • Field Detail

      • VALID

        static final ConstraintValidator VALID
        A constraint validator that just returns the object as being valid.
    • Method Detail

      • isValid

        boolean isValid​(@Nullable
                        T value,
                        @NonNull
                        io.micronaut.core.annotation.AnnotationValue<A> annotationMetadata,
                        @NonNull
                        ConstraintValidatorContext context)
        Implements the validation logic.

        Implementations should be thread-safe and immutable.

        Parameters:
        value - object to validate
        annotationMetadata - The annotation metadata
        context - The context object
        Returns:
        false if value does not pass the constraint
      • isValid

        default boolean isValid​(T value,
                                javax.validation.ConstraintValidatorContext context)
        Specified by:
        isValid in interface javax.validation.ConstraintValidator<A extends java.lang.annotation.Annotation,​T>