Interface Validator<T>

Type Parameters:
T - type of value checked
All Superinterfaces:
BodyValidator<T>
All Known Implementing Classes:
JakartaValidation, Rules
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<T> extends BodyValidator<T>
Checks a value and reports field violations.

Implementations must be thread-safe and must not retain the value. The returned list is empty when the value is valid; otherwise it holds at most Validation.MAX_VIOLATIONS violations whose fields are property paths built from developer-defined names and element indexes and whose codes are fixed machine-readable strings. Violations are sent to clients, so they must never contain the checked value or any other client input (no map keys, no messages). An implementation that fails internally should throw an AxiomException, typically InternalServerErrorException, whose response carries no internal detail; other exceptions reach the server's generic 500 handling.

A validator is also core's BodyValidator, so it can check request bodies directly: ctx.validatedBody(Order.class, ORDER).

  • Method Summary

    Modifier and Type
    Method
    Description
    default Validator<T>
    and(Validator<? super T> other)
    Returns a validator that runs this validator and then other, keeping the first occurrence of each violation and stopping once Validation.MAX_VIOLATIONS are collected (later validators are then not run).
    validate(T value)
    Checks a value.
  • Method Details

    • validate

      List<Violation> validate(T value)
      Checks a value.
      Specified by:
      validate in interface BodyValidator<T>
      Parameters:
      value - value to check; may be null, but never null when called by ctx.validatedBody
      Returns:
      immutable or caller-owned violations, empty when the value is valid; never null and without null elements (callers fail with IllegalStateException otherwise)
    • and

      default Validator<T> and(Validator<? super T> other)
      Returns a validator that runs this validator and then other, keeping the first occurrence of each violation and stopping once Validation.MAX_VIOLATIONS are collected (later validators are then not run).
      Parameters:
      other - validator to run second
      Returns:
      combined validator returning an immutable list