[英]How to ignore JSON processing for a request in Spring MVC?
I have a request handler for which I would like to skip json processing and retrieve the request body as a string. 我有一个请求处理程序,我想跳过该请求处理程序,并以字符串的形式检索请求主体。 Eg - 例如-
@RequestMapping(value = "/webhook", method = RequestMethod.POST)
public void webHook(@RequestBody String body) {
}
However, the above method definition doesnt work as Spring forcibly tries to parse the posted string as json and thus throws an exception. 但是,上述方法定义不起作用,因为Spring强制尝试将发布的字符串解析为json并因此引发异常。
How do i tell spring to skip json processing for this request? 我如何告诉Spring跳过此请求的json处理?
use like this it'll work. 这样使用就可以了。
@RequestMapping(value = "/webhook", method = RequestMethod.POST)
public void webHook(HttpServletRequest request) {
String body = IOUtils.toString( request.getInputStream());
// do stuff
}
Not using @RequestBody
is key here. 这里不使用@RequestBody
是关键。 When spring sees @RequestBody
it tries to map the entire body as object. 当spring看到@RequestBody
它将尝试将整个身体映射为对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.