我认为使用杰克逊图书馆,您可以执行以下操作。
@RequestMapping(value = "/getjson", method = RequestMethod.GET, produces="application/json")@ResponseBodypublic String getJson() { //your logic ObjectMapper mapper = new ObjectMapper(); return mapper.writevalueAsString(json);}@RequestMapping(value = "/post", method = RequestMethod.POST, produces="application/json", consumes="application/json")@ResponseBodypublic String post(@RequestBody String json) { POJO pj = new POJO(); ObjectMapper mapper = new ObjectMapper(); pj = mapper.readValue(json, POJO.class); //do some things with json, put some header information in json return mapper.writevalueAsString(pj);}


