Class ValidatorImpl

  • All Implemented Interfaces:
    ExecutableValidator, Validator

    public class ValidatorImpl
    extends Object
    implements Validator, ExecutableValidator
    The main Bean Validation class. This is the core processing class of Hibernate Validator.
    Author:
    Emmanuel Bernard, Hardy Ferentschik, Gunnar Morling, Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI, Guillaume Smet
    • Method Detail

      • validate

        public final <T> Set<ConstraintViolation<T>> validate​(T object,
                                                              Class<?>... groups)
        Description copied from interface: Validator
        Validates all constraints on object.
        Specified by:
        validate in interface Validator
        Type Parameters:
        T - the type of the object to validate
        Parameters:
        object - object to validate
        groups - the group or list of groups targeted for validation (defaults to Default)
        Returns:
        constraint violations or an empty set if none
      • validateProperty

        public final <T> Set<ConstraintViolation<T>> validateProperty​(T object,
                                                                      String propertyName,
                                                                      Class<?>... groups)
        Description copied from interface: Validator
        Validates all constraints placed on the property of object named propertyName.
        Specified by:
        validateProperty in interface Validator
        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)
        groups - the group or list of groups targeted for validation (defaults to Default)
        Returns:
        constraint violations or an empty set if none
      • validateParameters

        public <T> Set<ConstraintViolation<T>> validateParameters​(T object,
                                                                  Method method,
                                                                  Object[] parameterValues,
                                                                  Class<?>... groups)
        Description copied from interface: ExecutableValidator
        Validates all constraints placed on the parameters of the given method.
        Specified by:
        validateParameters in interface ExecutableValidator
        Type Parameters:
        T - the type hosting the method to validate
        Parameters:
        object - the object on which the method to validate is invoked
        method - the method for which the parameter constraints is validated
        parameterValues - the values provided by the caller for the given method's parameters
        groups - the group or list of groups targeted for validation (defaults to Default)
        Returns:
        a set with the constraint violations caused by this validation; will be empty if no error occurs, but never null
      • validateConstructorParameters

        public <T> Set<ConstraintViolation<T>> validateConstructorParameters​(Constructor<? extends T> constructor,
                                                                             Object[] parameterValues,
                                                                             Class<?>... groups)
        Description copied from interface: ExecutableValidator
        Validates all constraints placed on the parameters of the given constructor.
        Specified by:
        validateConstructorParameters in interface ExecutableValidator
        Type Parameters:
        T - the type hosting the constructor to validate
        Parameters:
        constructor - the constructor for which the parameter constraints is validated
        parameterValues - the values provided by the caller for the given constructor's parameters
        groups - the group or list of groups targeted for validation (defaults to Default)
        Returns:
        a set with the constraint violations caused by this validation; Will be empty if no error occurs, but never null
      • validateConstructorReturnValue

        public <T> Set<ConstraintViolation<T>> validateConstructorReturnValue​(Constructor<? extends T> constructor,
                                                                              T createdObject,
                                                                              Class<?>... groups)
        Description copied from interface: ExecutableValidator
        Validates all return value constraints of the given constructor.
        Specified by:
        validateConstructorReturnValue in interface ExecutableValidator
        Type Parameters:
        T - the type hosting the constructor to validate
        Parameters:
        constructor - the constructor for which the return value constraints is validated
        createdObject - the object instantiated by the given method
        groups - the group or list of groups targeted for validation (defaults to Default)
        Returns:
        a set with the constraint violations caused by this validation; will be empty, if no error occurs, but never null
      • validateReturnValue

        public <T> Set<ConstraintViolation<T>> validateReturnValue​(T object,
                                                                   Method method,
                                                                   Object returnValue,
                                                                   Class<?>... groups)
        Description copied from interface: ExecutableValidator
        Validates all return value constraints of the given method.
        Specified by:
        validateReturnValue in interface ExecutableValidator
        Type Parameters:
        T - the type hosting the method to validate
        Parameters:
        object - the object on which the method to validate is invoked
        method - the method for which the return value constraints is validated
        returnValue - the value returned by the given method
        groups - the group or list of groups targeted for validation (defaults to Default)
        Returns:
        a set with the constraint violations caused by this validation; will be empty if no error occurs, but never null
      • getConstraintsForClass

        public final BeanDescriptor getConstraintsForClass​(Class<?> clazz)
        Description copied from interface: Validator
        Returns the descriptor object describing bean constraints.

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

        Specified by:
        getConstraintsForClass in interface Validator
        Parameters:
        clazz - class or interface type evaluated
        Returns:
        the bean descriptor for the specified class
      • unwrap

        public final <T> T unwrap​(Class<T> type)
        Description copied from interface: Validator
        Returns an instance of the specified type allowing access to provider-specific APIs.

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

        Specified by:
        unwrap in interface Validator
        Type Parameters:
        T - the type of the object to be returned
        Parameters:
        type - the class of the object to be returned
        Returns:
        an instance of the specified class
      • forExecutables

        public ExecutableValidator forExecutables()
        Description copied from interface: Validator
        Returns the contract for validating parameters and return values of methods and constructors.
        Specified by:
        forExecutables in interface Validator
        Returns:
        contract for method and constructor validation