users@jersey.java.net

[Jersey] Re: returning default jersey responses as json

From: Bobby Bissett <bbissett_at_gmail.com>
Date: Mon, 30 Nov 2015 14:51:04 -0500

On Wed, Nov 18, 2015 at 8:13 PM, Joe Mocker <jmocker_at_tremorvideo.com> wrote:

> In Jersey 1.x As I recall if Jersey doesn't find a matching Resource for
> the request, it issues something like a WebApplicationException or
> something like that.
>

Thanks, this worked very well. An ExceptionMapper<Throwable> catches a
NotFoundException for a 404, and general WebApplicationException for a 405,
so I can easily stop those from generating the Response and send my own to
be consistent. (Bonus, when my code totally fails and throws something
random it's caught there and a nice 500 message gets sent back.)

I was a little surprised to see that, when I throw my subclass of
WebApplicationException that generates JSON, it doesn't get sent to the
exception mapper. But it makes sense that Jersey has already gotten the
response from it and doesn't need to call the mapper.

Thanks all for your help.

Cheers,
Bobby