Class ValidationException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.apache.juneau.http.response.BasicHttpException
org.apache.juneau.http.response.BadRequest
org.apache.juneau.rest.server.validation.ValidationException
- All Implemented Interfaces:
Serializable,HttpResponseMessage
Specialization of
BadRequest thrown by BeanValidator when one or more Jakarta Bean Validation
constraints on a @Content, @FormData, or @Request-bound parameter are violated.
Behaves like a plain 400 Bad Request from the wire's perspective — same status code, same reason
phrase, same default JSON envelope shape used by the rest of the framework's exception path — but adds a
structured, serialized violations list so the response body can include the list of
field-level errors that produced the failure.
Wire shape:
The response body 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 populated fromgetViolations(). - Problem-details OFF (default) —
application/jsonwith a simple{ "status":400, "errors":[ ... ] }envelope.
See Also:
- Since:
- 10.0.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.juneau.http.response.BadRequest
BadRequest.Unmodifiable -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default detail message used when constructed without an explicit message.Fields inherited from class org.apache.juneau.http.response.BadRequest
REASON_PHRASE, STATUS_CODE -
Constructor Summary
ConstructorsConstructorDescriptionValidationException(List<ValidationViolation> violations) Constructor.ValidationException(List<ValidationViolation> violations, String msg, Object... args) Constructor with a custom detail message. -
Method Summary
Modifier and TypeMethodDescriptionReturns a defensive, mutable copy of the violation list for callers that need to inspect / filter it without mutating the exception's own state.Returns the immutable list of constraint violations that produced this exception.Methods inherited from class org.apache.juneau.http.response.BadRequest
unmodifiableMethods inherited from class org.apache.juneau.http.response.BasicHttpException
addHeader, addHeader, equals, freeze, getBody, getFullStackMessage, getHeaders, getLocale, getMessage, getRootCause, getStatusCode, getStatusLine, hashCode, isUnmodifiable, modify, setBody, setContent, setContent, setHeader, setHeader, setHeaders, setHeaders, setLocale, setProtocolVersion, setReasonPhrase, setStatusCode, setStatusLine, toStringMethods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTraceMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.juneau.http.response.HttpResponseMessage
getFirstHeader, getHeaders
-
Field Details
-
DEFAULT_MESSAGE
The default detail message used when constructed without an explicit message.- See Also:
-
-
Constructor Details
-
ValidationException
Constructor.- Parameters:
violations- The list of constraint violations. Must not benull (use an empty list to signal "validation requested but no violations" — though that case never actually throws in practice).
-
ValidationException
Constructor with a custom detail message.- Parameters:
violations- The list of constraint violations. Must not benull .msg- The detail message. May benull . Treated as a format pattern whenargsis non-empty.args- Optional message arguments.
-
-
Method Details
-
getViolations
Returns the immutable list of constraint violations that produced this exception.- Returns:
- The list of violations, never
null and never modifiable.
-
copyViolations
Returns a defensive, mutable copy of the violation list for callers that need to inspect / filter it without mutating the exception's own state.- Returns:
- A new mutable copy. Never
null .
-