我想向 CXF (2.6.1) 添加一个 ExceptionMapper,它不仅可以传达响应代码,而且还以有效负载格式发送异常(我现在使用的是 JSON)。
@Provider
public class CustomExceptionMapper
implements
ExceptionMapper<MyException>
{
...
@Override
public Response toResponse(MyException mex)
{
//I need something here which can convert mex object to JSON and ship it in response
// I want this to be de-serialized on client
//the following returns the status code
return Response.status(Response.Status.BAD_REQUEST).build();
}
...
}
有没有办法做到这一点 ?