I am very new for spring mvc and java. i want to return a json data instead of string
@RequestMapping(value = "/ex/foos", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public String getFoosAsJsonFromREST() {
return "{\"name\":\"MyNode\", \"width\":200, \"height\":100}";
}
actual output:"{\"name\":\"MyNode\", \"width\":200, \"height\":100}"
output i want:{"name":"MyNode", "width":200, "height":100}
i followed the link but i still can't get literal json output
@RequestMapping(value = "/ex/foos", method = RequestMethod.GET, produces = "application/json") @ResponseBody public JsonNode getFoosAsJsonFromREST() {
String everything = "{\"a\":2,\"b\":\"astring\",\"c\":6}";
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree(everything);
return node;
}
output { "result": false, "message": "Unexpected end-of-String when base64 content\n at [Source: N/A; line: -1, column: -1]" }