泽西岛没有捕获异常

时间:2017-11-13 18:17:43

标签: java exception jax-rs jersey-2.0

ExceptionMapper的实现如下所示:

@Provider
public class CaptureUnhandledExceptions implements ExceptionMapper<Throwable>
{
    private static final Logger LOGGER = LogFactory.getLogger(CaptureUnhandledExceptions.class);

    @Override
    public Response toResponse(Throwable exception)
    {
        LOGGER.error("Unhandled exception", exception);
        ErrorMessage em = new ErrorMessage(50099, ExceptionUtils.getRootCause(exception).getMessage(),
                exception.getMessage());
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(em).build();
    }
}

在我的REST api中,我正在尝试为我的JSON正文传递错误的值,但它正在抛出异常

Can not deserialize value of type com.abccompany.model.ConnectionEndpoint$Binding from String "RandomValue: value not one of declared Enum instance names: [POST, REDIRECT]
 at [Source: org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@3fce79f3; line: 16, column: 28] (through reference chain: com.abccompany.model.SpConnection["connection"]->com.abccompany.model.Connection["connectionendpoints"]->java.util.ArrayList[0]->com.abccompany.model.ConnectionEndpoint["endpointbinding"])
我错过了什么?我是否必须在ResourceConfig注册我的提供商?

在应用程序的ResourceConfig中

this.register(com.abccompany.utils.CaptureUnhandledExceptions.class);

1 个答案:

答案 0 :(得分:0)

修复方法是在this.register(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJs‌​onProvider.class);

中添加ResourceConfig