[Jersey] Re: Mapping exceptions thrown from JaxB bean methods

From: Pavel Bucek <>
Date: Wed, 08 Feb 2012 17:49:00 +0100


I think main problem here is when is that exception thrown - is it
during marshalling/unmarshalling? (MessageBodyReader/Writer invocation).

There might be a problem, because we could end up in infinite loop if
we'd let handle exception mappers exceptions thrown during serializing a

Additionally, see chapter 3.3.4, bullet 2 in JAX-RS spec:


    Unchecked exceptions and errors MUST be re-thrown and allowed to
    propagate to the underlying container.

So to answer - its by design. If you can, share additional details of
your app and what do you want to achieve and we might be able to give a
better advice.


On 2/2/12 9:18 PM, wrote:
> I have an ExceptionMapper for my custom exception (which extends
> RuntimeException).
> When my exception is thrown from a resource method (annotated with
> @Path ), it is correctly mapped through my instance of ExceptionMapper.
> However, when my exception is thrown from @XmlAttribute-annotated
> method in a JaxB bean (which in turn is returned by a resource method),
> no mapping occurs.
> Is this by design?
> The current way to affect errors returned from JaxB methods seems to
> wrap them into WebApplicationException which seems sub-optimal.
> Is there any other way to map the exceptions from JaxB bean methods?