How to customize error response when deserializing failed

后端 未结 1 433
自闭症患者
自闭症患者 2021-01-25 15:58

I have a jaxrs endpoint service, in my own ResourceConfig I register an ExceptionMapper, so when somewhere wrong happened, it will return a JSON

相关标签:
1条回答
  • 2021-01-25 16:26

    The Jackson provider already has ExceptionMappers1 that will just return the exception message when an exception is caught. If you want, you can just create your own ExceptionMapper for these exceptions, i.e. JsonParseException and JsonMappingException, and just return the message you want. Then just register those mappers with the Jersey application. This should override the ones registered by Jackson.

    The reason your exception mapper doesn't work is because the ones from Jackson are more specific. The more specific one always gets invoked.

    1 - namely JsonParseExceptionMapper and JsonMappingExceptionMapper

    0 讨论(0)
提交回复
热议问题