Class ValidationException


public class ValidationException extends ResponseStatusException

A request whose input broke its declared constraints.

Thrown by the generated router before the controller method runs, so nothing the method does happens for invalid input. An @ExceptionHandler for it may shape the answer; unhandled, the request is answered 400 with

{"status":400,"error":"Bad Request",
 "errors":[{"field":"address.zip","code":"Size","message":"size must be between 5 and 5"}]}

An application may throw it too, for a check no annotation expresses.

  • Constructor Details

    • ValidationException

      public ValidationException(List<FieldError> errors)
      Parameters:
      errors - what failed; at least one
  • Method Details

    • getFieldErrors

      public List<FieldError> getFieldErrors()
      Every constraint that failed, in the order the checks ran.
      Returns:
      the errors, never empty
    • getFieldErrors

      public List<FieldError> getFieldErrors(String field)
      The errors for one path.
      Parameters:
      field - the path
      Returns:
      its errors, possibly empty
    • toResponse

      public HttpServer.Response toResponse(HttpServer.Request request)
      The default answer: 400 with the errors as JSON.
      Parameters:
      request - the request being answered
      Returns:
      the response