@RequestBody
has a required attribute whose default value is true.
For example, if the following API is defined (the API that returns the request as it is) and you send an "empty" request to it, the default value will be ʻorg.springframework.http.converter. I get an HttpMessageNotReadableException`.
@PostMapping(path = "/hogehoge",
consumes = "text/plain; charset=UTF-8",
produces = "text/plain; charset=UTF-8")
@ResponseBody
public String execute(@RequestBody String body) {
return body;
}
By setting @RequestBody (required = false)
, you can handle empty requests as well. By the way, for an empty request, the body will be null.
Recommended Posts