All Known Implementing Classes:
Jsr380Validator
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Validator
Strategy interface for validating message payloads and other objects prior to handler invocation.

Implementations of this interface are typically invoked by the ValidatingInterceptor, which is automatically registered by the Flux Capacitor client. Validation occurs before the message is passed to the handler method.

A Validator is responsible for detecting constraint violations and producing a ValidationException if applicable. It supports validation groups to selectively apply rules.

Usage

The validator may be used programmatically:

 validator.assertValid(new CreateUserCommand(...));
 

But more commonly, it is used implicitly:

  • When the ValidatingInterceptor is registered with the HandlerFactory
  • Or when using dependency injection or framework-level validation support

Custom Implementations

Custom validators can be created to support use cases like:
  • JSR 380 / Bean Validation annotations (e.g., @NotNull, @Size)
  • Domain-specific validation rules
  • Structural validation on incoming web requests

This interface is designed to be functional and composable, enabling fluent use within client applications.

See Also:
  • Method Details

    • checkValidity

      <T> Optional<ValidationException> checkValidity(T object, Class<?>... groups)
      Validates the given object and returns an optional ValidationException if the object is invalid.
      Type Parameters:
      T - the type of object being validated
      Parameters:
      object - the object to validate
      groups - optional validation groups to apply
      Returns:
      an Optional containing the validation error if validation failed, or empty if valid
    • assertValid

      default <T> T assertValid(T object, Class<?>... groups) throws ValidationException
      Validates the given object and throws a ValidationException if it is invalid.
      Type Parameters:
      T - the type of object being validated
      Parameters:
      object - the object to validate
      groups - optional validation groups to apply
      Returns:
      the original object if valid
      Throws:
      ValidationException - if the object is invalid
    • isValid

      default boolean isValid(Object object, Class<?>... groups)
      Checks whether the given object is valid according to the defined validation rules.
      Parameters:
      object - the object to validate
      groups - optional validation groups to apply
      Returns:
      true if the object is valid, false otherwise