Class Validation

java.lang.Object
dev.relism.flash.ext.validation.Validation

public final class Validation extends Object
The validation service. Resolve it with require(Validation.class).

 CreateUser dto = validation.body(req, CreateUser.class);   // parse + verify
 

Constraints are compiled the first time a type is seen and cached in a ClassValue, which the JVM stores beside the class itself — no map lookup, no lock, and the entry is collected with the class rather than pinning it. Every later request walks the compiled table.

  • Method Details

    • body

      public <T> T body(dev.relism.flash.models.Request request, Class<T> type) throws Exception
      Deserializes the request body into type and verifies its constraints.
      Throws:
      dev.relism.flash.exceptions.HttpException - 400 if the body is not valid JSON
      ValidationException - 422 if it parses but violates a constraint
      Exception
    • validate

      public <T> T validate(T value)
      Verifies an already-constructed value.
      Returns:
      value, so it can be used inline
      Throws:
      ValidationException - 422 on the first type's worth of failures
    • forType

      public Validator forType(Class<?> type)
      The compiled constraints of type. Useful to pre-warm a hot DTO at boot, or to check whether a type declares constraints at all.