users@jersey.java.net

[Jersey] returning default jersey responses as json

From: Bobby Bissett <bbissett_at_gmail.com>
Date: Wed, 18 Nov 2015 13:49:18 -0500

Hi all,

We're using Jersey 1.11 (as part of GlassFish 3.1.2.2) and we need to
return everything as JSON. That's easy enough to do for our normal
responses with @Produces, and I overrode WebApplicationException with our
own exception to produce JSON output.

But I can't figure out how to return JSON for other calls that don't reach
our code, for instance when a 404 or 405 is returned. Instead we have html
output for these. I tried adding a javax.servlet.Filter to look at the
responses and check their type/status/etc, but the responses were already
committed at that point so I can't change them.

I saw that Jersey 2.X has added some Filter objects that probably do what
I'd like. Is there something I can do with 1.11 as well?

Thanks,
Bobby