I have a JAX-RS project that uses Jackson to handle JSON conversions.
When Jackson throws an exception, he automatically returns a string describing the error.
Since I want to return a custom JSON object, I created an ExceptionMapper .
The problem is that it only detects an exception when I specify exactly what type of exception is thrown.
For example, when the JSON sent to the method contains an unknown property, this works:
public class MyExceptionMapper implements ExceptionMapper<UnrecognizedPropertyException>
But if I changed UnrecognizedPropertyExceptionto PropertyBindingException(which the first extends), it will not work.
In short:
How do I create a generic exception mapping engine that catches any exception thrown by Jackson (or any other component of my application, for that matter)?
source
share