Here's the situation:
- My RESTEasy and Jackson work great together.
- My RESTful classes implement ExceptionMapper and have a toResponse method for them.
- If I have a problem inside any of my RESTful methods, an Exception is thrown and caught by the toResponse method.
- I want the exception to turn into well-formatted XML or JSON (depending on the Accept header)
The problem is that I have no idea that the Accept header is inside the toResponse method. I know that I can extend the Exception class and pass the header as a variable that I can use in toResponse, but I was hoping there would be a more βcorrectβ way to do this. I tried adding the @Produces annotation to the toResponse method without success.
Has anyone successfully configured RESTEasy to easily return JSON or XML from a response?
Dan
source share