[英]Override default JSON parsing for POST request in Play Framework
I do use the great advantage of overriding
the onError
method in Global.java
to control all exception handling in my Play application. 我确实利用
overriding
Global.java
的onError
方法的巨大优势来控制Play应用程序中的所有异常处理。 Now, when I do a POST reques
t to my API
defining its Content-Type
as application/json
and using a malformatted JSON array
, I'll get a Bad Request For request 'POST /api/something' [Invalid Json]
on the client side but can't override this by my own onError
function as it obviously does not provoke a JsonParsingException
or alike. 现在,当我对我的
API
进行POST reques
请求,将其Content-Type
定义为application/json
并使用malformatted JSON array
,我将在上收到Bad Request For request 'POST /api/something' [Invalid Json]
的Bad Request For request 'POST /api/something' [Invalid Json]
客户端,但是无法通过我自己的onError
函数覆盖它,因为它显然不会引发JsonParsingException
或类似行为。
Does anybody know how I can replace the HTML Bad request page by, let's say my own JSON
array with an error message? 有人知道我如何用错误消息替换我的
JSON
数组吗? That would help me a lot! 那对我有很大帮助!
Thanks in advance, Steven 预先感谢,史蒂文
Play does obviously not throw an exception when malformatted JSON arrays are posted. 发布格式错误的JSON数组时,播放显然不会引发异常。 I decided to use the
onBadRequest
method as I did not find a way to intercept Play's default behaviour in order to throw an exception. 我决定使用
onBadRequest
方法,因为我没有找到一种方法来拦截Play的默认行为以抛出异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.