Package com.codename1.backend.validation


package com.codename1.backend.validation

Build-time checked constraints on controller input.

Put Valid on a @RequestBody or @ModelAttribute parameter, or a constraint such as NotBlank, Size, Min or Max directly on a @RequestParam, @PathVariable or @RequestHeader parameter, and the generated router checks it before the controller method runs. A failure is a ValidationException carrying a FieldError per broken constraint, with a stable path for each.

The checks are generated Java, not reflection, so they cost what a hand-written if costs and survive translation. Regular expressions are not among the constraints, because the backend's class library has none; check such a value in the method and throw a ValidationException yourself.

  • Class
    Description
    One constraint one value broke.
    An integral number -- byte, short, int, long or their boxes -- that must be at most Max.value().
    An integral number -- byte, short, int, long or their boxes -- that must be at least Min.value().
    A String or other CharSequence that must hold at least one character that is not whitespace.
    A CharSequence, collection, map or array that must hold at least one element.
    The value must not be null.
    The length of a CharSequence, or the size of a collection, map or array, must lie between Size.min() and Size.max(), inclusive.
    Validates the annotated value's own constraints.
    A request whose input broke its declared constraints.
    Collects the FieldErrors of one request.