Returning JSON or XML for Exceptions in Jersey Returning JSON or XML for Exceptions in Jersey json json

Returning JSON or XML for Exceptions in Jersey


For those with similar issues in the future ...

Turns out my code was OK in the end. I was pulling my hair out, so I rewrote this module, and was still not getting anywhere. My browser would just sit there and hang forever. I started inspecting the headers with LiveHTTPHeaders (firefox add-on), and noticed when this happened Content-Length was larger then zero. I then tested with hurl.it and found out the body was returning normally. The browser would handle the XML response fine, but wouldnt ever display the JSON (thus the hanging). This is fine for my purpose as this is purely an API for application consumption and not for users. There is information on mapping exceptions at the Jersey wiki.

HTTP/1.1 404 Not FoundContent-Type: application/jsonDate: Fri, 21 May 2010 06:39:28 GMTServer: Google FrontendCache-Control: private, x-gzip-ok=""Transfer-Encoding: chunked{    "errorCode": "404",     "errorMsg": "Could not retrieve entity of kind Location with key Location(10)"}