Interface Validator<T>

  • Type Parameters:
    T - the type of the object to validate

    public interface Validator<T>
    A validator for validating application-specific objects.

    This interface is inspired on Spring's Validator mechanism. However Hawaii's validator mechanism uses it's own ValidationResult instead of Spring's Errors for returning validation errors.

    Implementors should typically only implement validate(Object, ValidationResult) as other methods are already implemented using the interface's default methods.

    Since:
    2.0.0
    Author:
    Marcel Overdijk
    See Also:
    ValidationError, ValidationException, ValidationResult
    • Method Detail

      • validate

        default ValidationResult validate​(T object)
        Validates the supplied object.
        Parameters:
        object - the object to validate
        Returns:
        the validation result
      • validate

        void validate​(T object,
                      ValidationResult validationResult)
        Validates the supplied object.
        Parameters:
        object - the object to validate
        validationResult - the contextual state about the validation process
      • validateAndThrow

        default void validateAndThrow​(T object)
                               throws ValidationException
        Validates the supplied object.
        Parameters:
        object - the object to validate
        Throws:
        ValidationException - if the validation fails
      • validateAndThrow

        default void validateAndThrow​(T object,
                                      ValidationResult validationResult)
                               throws ValidationException
        Validates the supplied object.
        Parameters:
        object - the object to validate
        validationResult - the contextual state about the validation process
        Throws:
        ValidationException - if the validation fails
      • isValid

        default boolean isValid​(T object)
        Returns true if the validation of the supplied object succeeds.
        Parameters:
        object - the object to validate
        Returns:
        true if the validation of the supplied object succeeds