I have a JAX-RS project that uses Jackson to handle JSON conversions.
When Jackson throws an exception, it automatically returns a string with the error description.
Since I want to return a custom JSON object, I created an ExceptionMapper.
The problem is, it only catches the exception when I specify exactly the type of the Exception being thrown.
For example, when the JSON sent to a method contains an unknown property, this works:
public class MyExceptionMapper implements ExceptionMapper<UnrecognizedPropertyException>
But if I change UnrecognizedPropertyException
to PropertyBindingException
(which the first extends), it won't work.
In short:
How can I create a generic exception mapper that catches any exception thrown by Jackson (or any other component of my app, for that matter)?