Package org.apache.juneau.rest.server.validation
juneau-rest-server — declarative validation of request beans via
jakarta.validation.constraints.* annotations.
Off by default — opt in per parameter
Validation is off by default and never runs automatically. A BeanValidator
is only constructed when an arg resolver sees a @jakarta.validation.Valid (or Spring
@org.springframework.validation.annotation.Validated) annotation on a @Content, @FormData,
or @Request-bound parameter. Without that annotation:
- No
jakarta.validation.Validatoris created. - No constraint check is invoked.
- No runtime cost is paid — the request bean flows through the unmodified Juneau pipeline as if Jakarta Validation were not on the classpath at all.
There is no global "turn on validation for the whole resource" switch — opt-in is per-parameter
via @Valid. This is a deliberate behavior difference from Spring MVC (which auto-validates beans whose
type carries constraint annotations) and from the standard Jakarta cascade rules.
Dependency stance
juneau-rest-server declares jakarta.validation:jakarta.validation-api in provided
scope. A concrete provider (e.g. org.hibernate.validator:hibernate-validator) is not bundled
and must be added by the consumer when they want validation to actually run. When the provider is missing at
runtime, the integration degrades to a no-op — the request bean is returned unmodified and a warning is
logged on first attempted use.
Failure handling
A constraint violation throws ValidationException (a 400 Bad Request
subclass) carrying the list of ValidationViolation details. The
response body shape depends on whether RFC 7807 problem-details mode is enabled on the resource:
- Problem-details ON —
application/problem+jsonwith the standardstatus/title/detailmembers plus anerrors[]extension array. - Problem-details OFF (default) —
application/jsonwith a simple{ "status":400, "errors":[ ... ] }envelope.
See Also:
- Since:
- 10.0.0
-
ClassDescriptionStatic dispatcher for the optional Jakarta Bean Validation 3.x integration.Specialization of
BadRequestthrown byBeanValidatorwhen one or more Jakarta Bean Validation constraints on a@Content,@FormData, or@Request-bound parameter are violated.Wire-friendly snapshot of a single Jakarta Bean Validation constraint violation, suitable for inclusion in an HTTP error response body.