Interface Validator<T>

Type Parameters:
T - the type of the object to validate
All Known Implementing Classes:
JakartaValidationValidator

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
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    isValid(T object)
    Returns true if the validation of the supplied object succeeds.
    validate(T object)
    Validates the supplied object.
    void
    validate(T object, ValidationResult validationResult)
    Validates the supplied object.
    default void
    Validates the supplied object.
    default void
    validateAndThrow(T object, ValidationResult validationResult)
    Validates the supplied object.
  • Method Details

    • 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