Module io.helidon.validation


module io.helidon.validation
Helidon validation module.

Validation allows validating objects before they are used in business logic. This is achieved by either validating a type annotated with Validation.Validated, or by intercepting a method that has one of the constraint annotations (such as Validation.NotNull), or the Validation.Valid annotation to validate a type.

Constraints are implemented as services that implement the ConstraintValidator contract, and that are named with the fully qualified name of the constraint annotation. Build-in validators have lower than default weight, so they can be overridden by custom validators.

To enable validation of a type, it MUST be annotated with Validation.Validated, and Helidon declarative codegen must be on the annotation processor path. This will generate a type validator service.

To enable interception of validated methods, the method, its parameter, or a generic type argument must be annotated with one of the constraints in Validation class, or the Validation.Valid annotation, and the same codegen module must be on the annotation processor path.

The constraints are grouped (through container classes) based on types that can be constrained. Some constraints are for convenience - such as Validation.Integer.Max and Validation.Long.Max - this allows usage of properly typed constants, as the general number constraint Validation.Number.Max must use a String value (as it can be used for any number, ranging from Byte to a BigDecimal.

Object constraints

Any type can be annotated with (see details in the following list):

String constraints

The following constraints can be used on String and CharSequence:

Integer constraints

The following constraints can be used on Integer, Long, Short, Byte, and Character: Note that byte is always considered to be unsigned (i.e. values are from 0 to 255 inclusive).

Long constraints

The following constraints can be used ONLY on Long:

Number constraints

The following constraints can be used on Number and its implementations: Note that byte is always considered to be unsigned (i.e. values are from 0 to 255 inclusive).