users@jersey.java.net

[Jersey] Re: returning default jersey responses as json

From: Joe Mocker <jmocker_at_Tremorvideo.com>
Date: Wed, 18 Nov 2015 22:56:34 +0000

If its not reaching your code, and so I'm guessing not even reaching Jersey, you'll probably have to add some custom error pages to your web.xml -

http://stackoverflow.com/questions/7066192/how-to-specify-the-default-error-page-in-web-xml

I presume you can just as easily return a JSON file as you can return HTML this way…

  --joe

From: Bobby Bissett <bbissett_at_gmail.com<mailto:bbissett_at_gmail.com>>
Reply-To: "users_at_jersey.java.net<mailto:users_at_jersey.java.net>" <users_at_jersey.java.net<mailto:users_at_jersey.java.net>>
Date: Wednesday, November 18, 2015 at 10:49 AM
To: "users_at_jersey.java.net<mailto:users_at_jersey.java.net>" <users_at_jersey.java.net<mailto:users_at_jersey.java.net>>
Subject: [Jersey] returning default jersey responses as json

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