简体   繁体   English

处理Jersey中的JSON解析错误

[英]Handle JSON parse error in Jersey

How can I intercept a parse error in my Jersey REST application? 如何拦截Jersey REST应用程序中的解析错误? I already registered an ExceptionMapper<Exception> but those don't get caught. 我已经注册了ExceptionMapper<Exception>但是没有被捕获。

It returns the following to the client 它将以下内容返回给客户端

Unexpected character ('y' (code 121)): expected a valid value (number,
  String, array, object, 'true', 'false' or 'null')
  at [Source: org.apache.catalina.connector.CoyoteInputStream@161d5f3;
  line: 1, column: 92]

But I want to send my own Response. 但我想发送自己的回复。

I'm guessing however your ExceptionMapper is registered, it isn't being applied to other packages, where you're invoking the Jersey library code to parse JSON. 我猜你的ExceptionMapper已经注册,它没有被应用到其他包,你正在调用Jersey库代码来解析JSON。

Surround all calls to Jersey for parsing in a Try{ }catch() block, where the catch should return an error code and not process further. 围绕所有对Jersey的调用以在Try {} catch()块中进行解析,其中catch应返回错误代码而不进一步处理。

Alternatively, it looks like Tomcat might be throwing the error before it even gets to your application. 或者,看起来Tomcat可能会在它到达您的应用程序之前抛出错误。 Maybe an issue with the way it is configured, or the way the client is communicating? 可能是配置方式或客户端通信方式有问题? Is this plaintext HTTP? 这是明文HTTP吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM