For my REST api, I use jersey and ExceptionMapper to detect global exceptions. It works fine in all exceptions thrown by my application, but I cannot catch the exception thrown by jackson.
For example, one of my endpoints takes an object containing an enumeration. If Json in the request has a value that is not in the enumeration, introduce this exception
Can not construct instance of my.package.MyEnum from String value 'HELLO': value not one of declared Enum instance names: [TEST, TEST2] at [Source: org.glassfish.jersey.me ssage.internal.ReaderInterceptorExecutor$UnCloseableInputStream@ 5922e236; line: 3, column: 1] (through reference chain: java.util.HashSet[0]->....)
Even if I created this mapper
@Provider @Component public class JacksonExceptionMapper implements ExceptionMapper<JsonMappingException> { @Override public Response toResponse(JsonMappingException e) { .... } }
Code never reaches this converter.
Is there something we need to do to catch these exceptions?
EDIT Note. My Jus tried to be less general, and instead of JsonMappingException I use InvalidFormatException, in this case mapper is called. But I still don't get it, because InvalidFormatException extends JsonMappingException and should also be thrown
source share