Class JakartaValidation

java.lang.Object
com.jsgalactic.axiom.validation.jakarta.JakartaValidation
All Implemented Interfaces:
BodyValidator<Object>, Validator<Object>, AutoCloseable

public final class JakartaValidation extends Object implements Validator<Object>, AutoCloseable
A Validator backed by Jakarta Validation annotations, using Hibernate Validator.

 record CreateUser(@NotBlank @Size(max = 80) String name, @Valid List<@NotNull Item> items) {}

 static final JakartaValidation VALIDATION = JakartaValidation.create();
 var user = Validation.require(VALIDATION, command);
 

Constraints may be placed on record components, fields and container elements; @Valid cascades into nested objects and collection elements. Put it on the type argument ( List<@Valid Item>): @Valid List<Item> also cascades, but the provider logs deprecation warning HV000271, which is left visible on purpose. Groups and group sequences are passed to create(Class[]); a class-level @GroupSequence redefining the default group is honored. Executable validation (method parameters and return values) is not offered: this validator checks values only. Each constraint violation becomes a Violation whose field is the property path (items[2].sku; map keys and set positions are omitted, class-level constraints report the object's path or, for the validated value itself, the empty FieldPath.ROOT) and whose code is the constraint annotation's simple name in snake case ( NotBlank becomes not_blank, DecimalMin becomes decimal_min). Provider messages and invalid values are never read into violations. Message interpolation is disabled entirely, no Expression Language implementation is used, and META-INF/validation.xml is ignored, so a template containing ${...} is never evaluated. Violations are sorted by field and code and capped at Validation.MAX_VIOLATIONS. A null value is reported as not_null on the whole value.

Instances are thread-safe and meant to be created once at startup and shared; creation bootstraps the provider and is comparatively expensive. Close the instance when the application stops to release the provider's caches. If the provider fails while validating, for example because a constraint is declared on an unsupported type or a constraint implementation throws, validate(Object) throws an InternalServerErrorException with code internal_server_error; the provider's exception is attached as its cause for logging and is never sent to clients.