开发者

Easy way to return JSON from ExceptionMapper in RestEasy?

开发者 https://www.devze.com 2023-02-25 15:28 出处:网络
Here\'s the situation: I have RESTEasy and Jackson working together beautifully My RESTful classes implement ExceptionMapper and have a toResponse method on them.

Here's the situation:

  1. I have RESTEasy and Jackson working together beautifully
  2. My RESTful classes implement ExceptionMapper and have a toResponse method on them.
  3. If I have a problem inside any of my RESTful methods an Exception is thrown and caught by the toResponse method.
  4. I'd like the exception to turn into nicely formatted XML or JSON (depending on the Accept header)

The problem is I have no idea what the Accept header is inside the toResponse method. I know I can extend the Exception class and pass the header in as a variable, which I can then use in toResponse, but I was hoping there would be a more 'correct' way to do this. I've tried adding the @Produces annotation to the toResponse method without success.

Has anyone successfully configured RESTEasy to easily return JSO开发者_StackOverflow中文版N or XML from toResponse?

-Dan


Nevermind, I found the answer. I must have worded my question poorly, but I will leave this around in case someone stumbles upon it.

Here's the answer: JAX-RS (Jersey) custom exception with XML or JSON

0

精彩评论

暂无评论...
验证码 换一张
取 消