Module io.helidon.validation
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):Validation.Valid- as long as the class/interface isValidation.Validated, will validate the instance (deep validation)Validation.NotNull- will check that the value is not nullValidation.Null- will check that the value is null
String constraints
The following constraints can be used onString and CharSequence:
Validation.String.Length- minimal and/or maximal lengthValidation.String.NotBlank- will check that the value is not blankValidation.String.NotEmpty- will check that the value is not emptyValidation.String.Pattern- will check that the value matches the regular expressionValidation.String.Email- will check that the value matches e-mail structure
Integer constraints
The following constraints can be used onInteger,
Long, Short, Byte, and Character:
Validation.Integer.Max- maximal valueValidation.Integer.Min- minimal value
Long constraints
The following constraints can be used ONLY onLong:
Validation.Long.Max- maximal valueValidation.Long.Min- minimal value
Number constraints
The following constraints can be used onNumber and its implementations:
Validation.Number.Digits- max number of integer and fractional digitsValidation.Number.Max- maximal valueValidation.Number.Min- minimal valueValidation.Number.Negative- number must be negative (negative zero for longs is a zero)Validation.Number.NegativeOrZero- number must not be positiveValidation.Number.Positive- number must be positive (zero is not positive)Validation.Number.PositiveOrZero- number must be positive or zero (negative zero is OK)
-
Packages
Exports