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):

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/cart")
public class CartApiController {
    @GetMapping(path = "/get", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getCart() {
        return "{success: true}";
    }
}

that method getCart() is supposed to return "application/json" content type. If I check that within a browser, I find the follwing response header:

2020-03-30_10h06_50

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.

Comment From: rstoyanchev

This is a duplicate of #24123.