Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
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.
Types
class FieldError | One constraint one value broke. |
annotation Max | An integral number – byte, short, int, long or their boxes – that must be at most value. |
annotation Min | An integral number – byte, short, int, long or their boxes – that must be at least value. |
annotation NotBlank | A String or other CharSequence that must hold at least one character that is not whitespace. |
annotation NotEmpty | A CharSequence, collection, map or array that must hold at least one element. |
annotation NotNull | The value must not be null. |
annotation Size | The length of a CharSequence, or the size of a collection, map or array, must lie between min and max, inclusive. |
annotation Valid | Validates the annotated value’s own constraints. |
class ValidationException | A request whose input broke its declared constraints. |
class Violations | Collects the FieldErrors of one request. |