RestController returning JSON String producing incorrect Content-Type charset #24813
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: duplicate
A duplicate of another issue
Uh oh!
There was an error while loading. Please reload this page.
Affects: 5.2.2.RELEASE
(via spring-boot-starter 2.2.2.RELEASE - but would also affect the "master")
Hi,
I do have a
@RestController
annotated class which looks like this (removed any unrelevant things):that method getCart() is supposed to return "application/json" content type. If I check that within a browser, I find the follwing response header:
application/json;charset=ISO-8859-1
which is not right to my understanding.
I think, I have tracked it down to the following class:
https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java
Where on line 49 it states
public static final Charset DEFAULT_CHARSET = StandardCharsets.ISO_8859_1;
which causes this issue.
Our workaorund at the moment is to use the following annotation config insteadwhich enforces UTF-8:
@GetMapping(path = "/get", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
but that makes use of a deprecated (due to #22788) field , which we don't want to do obviously.
Is this supposed to be like that and if not can you maybe fix this?
Thanks and best regards.
The text was updated successfully, but these errors were encountered: