简体   繁体   中英

How to catch a JSONObject sent via POSTMAN in a Springboot application?

Following is my controller

@RestController
@RequestMapping("identity/v1/")
public class InvestigateTargetController {
  @RequestMapping(method = RequestMethod.POST, value = "receive",
  produces = OneplatformMediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResponseEntity<InvestigateOutputResource>
     processRequest(@RequestBody JSONObject jsonObject) {

    System.out.println(jsonObject.toString());
    return new ResponseEntity<>(HttpStatus.OK);

  }
}

I am trying to send a json object to this controller via POSTMAN. But when I print jsonObject.toString() the output is {} ( empty ). Following are snapshots of POSTMAN:

在此处输入图片说明 在此处输入图片说明

Where am I going wrong ?

创建一个具有与json对象相同的属性(带有getter和setter)的Java类,并将其作为requestbody。

Solved it. Instead of JSONObject catch it in a string type.

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