Class Validation

java.lang.Object
com.jsgalactic.axiom.validation.Validation

public final class Validation extends Object
Entry point for checking values in handlers.

 var command = Validation.require(CREATE_NOTE, parse(ctx));
 

A failed check throws core's ValidationException, which the server maps to a 422 application/problem+json response listing only each violation's field path and code.

  • Field Details

  • Method Details

    • require

      public static <T> T require(Validator<? super T> validator, T value)
      Checks a value and returns it when valid.
      Type Parameters:
      T - value type
      Parameters:
      validator - validator to run
      value - value to check; may be null if the validator accepts null
      Returns:
      value
      Throws:
      ValidationException - with at most MAX_VIOLATIONS violations, in the order the validator reported them, when the value is invalid
      IllegalStateException - if the validator returns null or a null violation
    • require

      public static <T> T require(String field, Validator<? super T> validator, T value)
      Checks one request parameter or header value and prefixes each violation's field path with the parameter name. This lets the same Validator rule set cover bodies (through require(Validator, Object)) and values already parsed by Context's typed path, query and header accessors, with paths such as query.q or header.X-Api-Key in the 422 problem response.
      Type Parameters:
      T - value type
      Parameters:
      field - safe property path naming the parameter; never derived from client input
      validator - validator to run
      value - parsed value to check; may be null if the validator accepts null
      Returns:
      value
      Throws:
      ValidationException - with at most MAX_VIOLATIONS violations, in the order the validator reported them, when the value is invalid
      IllegalStateException - if the validator returns null or a null violation