As mentioned for example in RFC 7159, strings etc primitive types are valid json messages on their own. But the string has to be encased in double quotes.
So, string:
test
in json is:
"test"
If I send a properly quoted POST body
"test"
to the following code
@RestController
@RequestMapping("test")
public class TestController{
@RequestMapping(method=RequestMethod.POST)
public ResponseEntity<?> userLogout(@RequestBody final String input) {
System.out.println(input);
return new ResponseEntity<>("OK", HttpStatus.OK);
}
}
the value of input variable is
"test"
instead of
test
which would be the correct value.
Also the output of the request is
OK
instead of
"OK"
which would be the correct output.
Any ideas how to force Spring to handle the strings properly?
The request does have the correct header:
Content-Type: application/json; charset=UTF-8
And adding produces="application/json" to the RequestMapping annotation didn't help.
(Just a side note: If you use retrofit or Gson for communication, they do handle strings properly.)