2

I have a dropwizard application with a global exception handler registered that implements ExceptionMapper<Throwable>. If I throw any runtime exception from within a resource the mapper gets hit.

However, in a test I am posting JSON to to a resource with a missing type discriminator for a jackson polymorphic type. Jersey is returning a 400, and I can see that a JsonProcessingException is being thrown when stepping through the code, but the global mapper isn't getting hit.

I tried to see if there were any other exception mappers registered and to try and unregister them, by checking the environment.jersey().getResourceConfig().getSingletons() set and there were no other exception mappers registered.

I've also tried creating a specific handler for just that exception but no dice. And even then that's kind of weird if I already have a global handler to catch all Throwable.

Has anyone encountered this?

--

EDIT:

looks like the dropwizard exception mapper does get registered and I somehow need to find out when in the lifecycle that happens and unregister it

devshorts
  • 8,572
  • 4
  • 50
  • 73

1 Answers1

3

Yes, you do need to override the exception mapper for JsonProcessingException (JsonProcessingExceptionMapper).

looks like the dropwizard exception mapper does get registered and I somehow need to find out when in the lifecycle that happens and unregister it

You can find out how to override an ExceptionMapper on this answer.

Community
  • 1
  • 1
Natan
  • 2,816
  • 20
  • 37
  • Perfect, thanks! I was wondering why I wasn't able to unregister them and its because I am using dropwizard 8 with jersey 2, so the flag in that answer is perfect. – devshorts May 29 '15 at 17:11