简体   繁体   中英

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.

How do i tell spring to skip json processing for this request?

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. When spring sees @RequestBody it tries to map the entire body as object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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