Skip to content

Commit ce49354

Browse files
committed
Sync MockHttpServletResponse implementations
See gh-33019
1 parent 1d363e5 commit ce49354

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.UnsupportedEncodingException;
2525
import java.io.Writer;
2626
import java.nio.charset.Charset;
27+
import java.nio.charset.StandardCharsets;
2728
import java.text.DateFormat;
2829
import java.text.ParseException;
2930
import java.text.SimpleDateFormat;
@@ -72,6 +73,8 @@ public class MockHttpServletResponse implements HttpServletResponse {
7273

7374
private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
7475

76+
private static final MediaType APPLICATION_PLUS_JSON = new MediaType("application", "*+json");
77+
7578

7679
//---------------------------------------------------------------------
7780
// ServletResponse properties
@@ -348,6 +351,10 @@ public void setContentType(@Nullable String contentType) {
348351
if (mediaType.getCharset() != null) {
349352
setExplicitCharacterEncoding(mediaType.getCharset().name());
350353
}
354+
else if (mediaType.isCompatibleWith(MediaType.APPLICATION_JSON) ||
355+
mediaType.isCompatibleWith(APPLICATION_PLUS_JSON)) {
356+
this.characterEncoding = StandardCharsets.UTF_8.name();
357+
}
351358
}
352359
catch (Exception ex) {
353360
// Try to get charset value anyway

0 commit comments

Comments
 (0)