简体   繁体   中英

How to return multiple ResponseEntity including JSONObject in Spring MVC?

如何在Spring MVC中返回包括JSONObject在内的多个ResponseEntity

CreateEndPoint is propably a simple java bean class with getters and setters and standard mapper does not have problem with serializing it to JSON. JSONObject is wrapper for map and does not provide simple getters and setters and mapper does not know what to do with that.

Instead of this:

return new ResponseEntity<org.json.JSONObject>(dataFromResponse,
                    HttpStatus.OK);

try this:

return new ResponseEntity<String>(dataFromResponse.toString(), HttpStatus.OK);

You can also try to provide additional a mapper which invokes toString() operation for given types instead of using getters and setters but I think this solution is more simple.

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