Use UTF-8 with JSON in MockHttpServletResponse
This commit makes MockHttpServletResponse consistent with the other parts of the framework where the body of a response is read as an UTF-8 String when the content type is application/json or similar, overriding the ISO-8859-1 default Servlet encoding. Closes gh-33019
This commit is contained in:
@@ -30,6 +30,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -620,4 +621,12 @@ class MockHttpServletResponseTests {
|
||||
assertThat(contentTypeHeader).isEqualTo("text/plain");
|
||||
}
|
||||
|
||||
@Test // gh-33019
|
||||
void contentAsStringEncodingWithJson() throws IOException {
|
||||
String content = "{\"name\": \"Jürgen\"}";
|
||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
response.getWriter().write(content);
|
||||
assertThat(response.getContentAsString()).isEqualTo(content);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user