Springboot @ RequestBody cannot get the content-type= "application/json" request data

now I want to get a content-type=application/json callback data. Oddly enough, I can"t get the data using @ RequestBody, as shown in the following code:

@Data
public class BaiduDocNofityResponse {
    private String messageId;
    private String messageBody;
    private String notification;
    private String server;

    private String subscriptionName;
    private String version;
    private String signature;
}

@PostMapping("/doc/notify")
public void notify(@RequestBody BaiduDocNofityResponse response){
    log.info(":");
    log.info(response.toString());//****

}

but if you replace it with the following code, you can get it:

@PostMapping("/doc/notify")
public void notify(HttpServletRequest request) throws IOException {
    log.info("request content-type=" + request.getContentType());
    log.info(":" + request.toString());
    InputStream is = request.getInputStream();
    String val = StreamUtil.inputStream2String(is, "UTF-8");
    log.info(val);//****
}

does anyone know why?

Feb.26,2021

is not sent to you in JSON/Body format, you can use @ ModelAttribute instead of @ RequestBody, to get the value in Form/URL format. And the two ways of dealing with special types of format such as dates are not quite the same.


solved. Since log.info (response.toString ()); / / toString () here) doesn't work, if you get response.messageBody directly, I'm really drunk

.
Menu