File tree 1 file changed +7
-0
lines changed
spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet
1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change 24
24
import java .io .UnsupportedEncodingException ;
25
25
import java .io .Writer ;
26
26
import java .nio .charset .Charset ;
27
+ import java .nio .charset .StandardCharsets ;
27
28
import java .text .DateFormat ;
28
29
import java .text .ParseException ;
29
30
import java .text .SimpleDateFormat ;
@@ -72,6 +73,8 @@ public class MockHttpServletResponse implements HttpServletResponse {
72
73
73
74
private static final TimeZone GMT = TimeZone .getTimeZone ("GMT" );
74
75
76
+ private static final MediaType APPLICATION_PLUS_JSON = new MediaType ("application" , "*+json" );
77
+
75
78
76
79
//---------------------------------------------------------------------
77
80
// ServletResponse properties
@@ -348,6 +351,10 @@ public void setContentType(@Nullable String contentType) {
348
351
if (mediaType .getCharset () != null ) {
349
352
setExplicitCharacterEncoding (mediaType .getCharset ().name ());
350
353
}
354
+ else if (mediaType .isCompatibleWith (MediaType .APPLICATION_JSON ) ||
355
+ mediaType .isCompatibleWith (APPLICATION_PLUS_JSON )) {
356
+ this .characterEncoding = StandardCharsets .UTF_8 .name ();
357
+ }
351
358
}
352
359
catch (Exception ex ) {
353
360
// Try to get charset value anyway
You can’t perform that action at this time.
0 commit comments