With #22100 (release 5.1.4) the StringHttpMessageConverter used charset UTF-8 for application/json, which is correct. However, the change to StringHttpMessageConverter.java was undone with #22954 (release 5.2.0).
That seems like a regression indeed. I can't see why https://github.com/spring-projects/spring-framework/commit/bc205e0dbf4b79e9dd2f3527ddfa9fb5a117cc67 dropped the charset defaulting to UTF-8 for JSON in StringHttpMessgageConverter. That isn't actually added to a header. @sdeleuze do you agree?
Tentatively scheduled for 5.2.3.
@rstoyanchev For the reading side, I agree and this is confirmed by an additional StringHttpMessageConverterTests#readJSON test I wrote. But while writing a StringHttpMessageConverterTests#writeJSON one, I figured out that we need potentially to take care about the writing side as well, since currently I think application/json is processed as application/json;charset=ISO-8859-1 due to the fact that StringHttpMessageConverter default charset is StandardCharsets.ISO_8859_1. And if we modify something here, we need to make sure the resulting content type header is application/json not application/json;charset=UTF-8 (implicit UTF-8 encoding).
Any thoughts?
Indeed, that should be the outcome. I'll add such tests and ensure they pass. Probably getDefaultCharset() could be overridden to return null for application/json if the default hasn't been set explicitly (i.e. is same as DEFAULT_CHARSET).
@sdeleuze note that the addition of charset=ISO-8859-1 when writing JSON was existing behavior that has always been there. I've changed it for 5.2.3 but for 5.1.x I will only backport the reading side change which is the regression reported here.
This was actually introduced in 5.2.0, so no need to backport. The reading side is already the same in 5.1.x.
Most helpful comment
Indeed, that should be the outcome. I'll add such tests and ensure they pass. Probably
getDefaultCharset()could be overridden to returnnullforapplication/jsonif the default hasn't been set explicitly (i.e. is same asDEFAULT_CHARSET).