Interface ProblemMapper<T extends Throwable>
- Type Parameters:
T- TheThrowablesubtype this mapper handles.
Throwable into an
RFC 7807 / 9457 Problem bean.
Implementations contribute domain-specific error translation without subclassing the request-processor chain.
A ProblemMapper bean is registered via the resource bean store (e.g. a @Bean ProblemMapper foo()
factory method on a @Rest-annotated resource, or any other mechanism that contributes named beans to
the resource's bean store); the server-side processor picks it up automatically when an opted-in operation
throws or returns a matching exception.
Discovery model
The processor collects all ProblemMapper beans visible from the resource's bean store, then picks the
most-specific mapper for the exception class hierarchy (a mapper whose getExceptionType() is the
closest superclass of the thrown exception wins; ties are broken by registration order, with the bean-store
walk order serving as the tiebreaker). Mappers that return null are skipped and the next-most-specific
mapper is tried, finally falling back to the default ProblemAdapters.fromException(...) adaptation in
juneau-rest-common for BasicHttpException subclasses.
Example:
See Also:
-
Method Summary
-
Method Details
-
getExceptionType
Returns the exception type this mapper handles.The processor matches mappers by checking
getExceptionType().isAssignableFrom(thrown.getClass())for each registered mapper, then picks the mapper whosegetExceptionType()sits closest to the thrown class in the hierarchy. Implementations usually return the same class their<T>parameter binds; declaring it explicitly here avoids reflective inspection of the generic type at runtime.- Returns:
- The exception class this mapper handles. Must not be
null .
-
map
Maps the supplied exception to aProblembean.Returning
null signals "no opinion on this exception"; the processor then tries the next-most-specific registered mapper (and, ultimately, the built-in default fallback). Returning a populatedProblemcauses the processor to emit that bean asapplication/problem+json.- Parameters:
exception- The exception to translate. Nevernull .- Returns:
- The
Problembean to emit, ornull to defer to the next mapper.
-