Package org.apache.juneau.rest.server.validation


package org.apache.juneau.rest.server.validation
Optional Jakarta Bean Validation 3.x integration for 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.Validator is 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+json with the standard status / title / detail members plus an errors[] extension array.
  • Problem-details OFF (default) — application/json with a simple { "status":400, "errors":[ ... ] } envelope.
See Also:
Since:
10.0.0
  • Class
    Description
    Static dispatcher for the optional Jakarta Bean Validation 3.x integration.
    Specialization of BadRequest thrown by BeanValidator when 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.