Interface Validator

All Superinterfaces:
jakarta.validation.Validator
All Known Implementing Classes:
DefaultAnnotatedElementValidator, DefaultValidator

public interface Validator extends jakarta.validation.Validator
Extended version of the Valid interface for Micronaut's implementation.

The Validator.getConstraintsForClass(Class) method is not supported by the implementation.

Since:
1.2
Author:
graemerocher
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Annotation used to define a constraint.
    static final String
    Annotation used to define an object as valid.
  • Method Summary

    Modifier and Type
    Method
    Description
    Overridden variation that returns a ExecutableMethodValidator.
    static @NonNull Validator
    Constructs a new default instance.
    <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>>
    validate(@NonNull io.micronaut.core.beans.BeanIntrospection<T> introspection, T object, @NonNull BeanValidationContext context)
    Validate the given introspection and object.
    <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>>
    validate(@NonNull io.micronaut.core.beans.BeanIntrospection<T> introspection, T object, @Nullable Class<?>... groups)
    Validate the given introspection and object.
    <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>>
    validate(T object, @NonNull BeanValidationContext validationContext)
    Validates all constraints on object.
    <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>>
    validate(T object, Class<?>... groups)
     
    <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>>
    validateProperty(T object, @NonNull String propertyName, BeanValidationContext context)
    Validates all constraints placed on the property of object named propertyName.
    <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>>
    validateProperty(T object, @NonNull String propertyName, Class<?>... groups)
     
    <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>>
    validateValue(@NonNull Class<T> beanType, @NonNull String propertyName, @Nullable Object value, BeanValidationContext context)
    Validates all constraints placed on the property named propertyName of the class beanType would the property value be value.
    <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>>
    validateValue(@NonNull Class<T> beanType, @NonNull String propertyName, @Nullable Object value, Class<?>... groups)
     

    Methods inherited from interface jakarta.validation.Validator

    getConstraintsForClass, unwrap
  • Field Details

    • ANN_VALID

      static final String ANN_VALID
      Annotation used to define an object as valid.
    • ANN_CONSTRAINT

      static final String ANN_CONSTRAINT
      Annotation used to define a constraint.
  • Method Details

    • forExecutables

      @NonNull @NonNull ExecutableMethodValidator forExecutables()
      Overridden variation that returns a ExecutableMethodValidator.
      Specified by:
      forExecutables in interface jakarta.validation.Validator
      Returns:
      The validator
    • validate

      @NonNull <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>> validate(@NonNull T object, Class<?>... groups)
      Specified by:
      validate in interface jakarta.validation.Validator
    • validate

      @NonNull <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>> validate(@NonNull T object, @NonNull @NonNull BeanValidationContext validationContext)
      Validates all constraints on object.
      Type Parameters:
      T - the type of the object to validate
      Parameters:
      object - object to validate
      validationContext - The context
      Returns:
      constraint violations or an empty set if none
      Throws:
      IllegalArgumentException - if object is null or if null is passed to the varargs groups
      jakarta.validation.ValidationException - if a non recoverable error happens during the validation process
    • validate

      @NonNull <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>> validate(@NonNull @NonNull io.micronaut.core.beans.BeanIntrospection<T> introspection, @NonNull T object, @Nullable @Nullable Class<?>... groups)
      Validate the given introspection and object.
      Type Parameters:
      T - The object type
      Parameters:
      introspection - The introspection
      object - The object
      groups - The groups
      Returns:
      The constraint violations
    • validate

      @NonNull <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>> validate(@NonNull @NonNull io.micronaut.core.beans.BeanIntrospection<T> introspection, @NonNull T object, @NonNull @NonNull BeanValidationContext context)
      Validate the given introspection and object.
      Type Parameters:
      T - The object type
      Parameters:
      introspection - The introspection
      object - The object
      context - The context
      Returns:
      The constraint violations
    • validateProperty

      @NonNull <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>> validateProperty(@NonNull T object, @NonNull @NonNull String propertyName, Class<?>... groups)
      Specified by:
      validateProperty in interface jakarta.validation.Validator
    • validateProperty

      @NonNull <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>> validateProperty(@NonNull T object, @NonNull @NonNull String propertyName, BeanValidationContext context)
      Validates all constraints placed on the property of object named propertyName.
      Type Parameters:
      T - the type of the object to validate
      Parameters:
      object - object to validate
      propertyName - property to validate (i.e. field and getter constraints)
      context - The context
      Returns:
      constraint violations or an empty set if none
      Throws:
      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
      jakarta.validation.ValidationException - if a non recoverable error happens during the validation process
    • validateValue

      @NonNull <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>> validateValue(@NonNull @NonNull Class<T> beanType, @NonNull @NonNull String propertyName, @Nullable @Nullable Object value, Class<?>... groups)
      Specified by:
      validateValue in interface jakarta.validation.Validator
    • validateValue

      @NonNull <T> @NonNull Set<jakarta.validation.ConstraintViolation<T>> validateValue(@NonNull @NonNull Class<T> beanType, @NonNull @NonNull String propertyName, @Nullable @Nullable Object value, BeanValidationContext context)
      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().

      Type Parameters:
      T - the type of the object to validate
      Parameters:
      beanType - the bean type
      propertyName - property to validate
      value - property value to validate
      context - The context
      Returns:
      constraint violations or an empty set if none
      Throws:
      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
      jakarta.validation.ValidationException - if a non recoverable error happens during the validation process
    • getInstance

      @NonNull static @NonNull Validator getInstance()
      Constructs a new default instance. Note that the returned instance will not contain managed ConstraintValidator instances and using Inject should be preferred.
      Returns:
      The validator.