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 FieldErrorOne constraint one value broke.
annotation MaxAn integral number – byte, short, int, long or their boxes – that must be at most value.
annotation MinAn integral number – byte, short, int, long or their boxes – that must be at least value.
annotation NotBlankA String or other CharSequence that must hold at least one character that is not whitespace.
annotation NotEmptyA CharSequence, collection, map or array that must hold at least one element.
annotation NotNullThe value must not be null.
annotation SizeThe length of a CharSequence, or the size of a collection, map or array, must lie between min and max, inclusive.
annotation ValidValidates the annotated value’s own constraints.
class ValidationExceptionA request whose input broke its declared constraints.
class ViolationsCollects the FieldErrors of one request.