Affects: 5.3.15
I am doing an "application/json" PUT request containing a plain JSON string (with a leading and a trailing double quote) in the body. I am not able to get the (JSON-decoded) string content (without the double quotes) using a correctly declared controller method:
@PutMapping(path = "/put", consumes = MediaType.APPLICATION_JSON_VALUE)
public void doPut(@RequestBody String string)
Instead this method always gives me the encoded JSON string with the double quotes.
I wonder why Spring behaves differently on JSON objects vs. JSON string literals. It seems that others stumbled about this problem too: https://stackoverflow.com/questions/64990357/parsing-a-request-body-containing-a-quoted-string-as-json-in-spring-boot-2
Comment From: bclozel
This is basically a duplicate of #27168.
From a content negotiation point of view, we can't know if the intent is to get the entire JSON input as a String (using the StringHttpMessageConverter
) or to get a single, deserialized, JSON String value. The same could be applied for other basic JSON types.