Sync MockHttpServletResponse implementations

See gh-33019
This commit is contained in:
Sam Brannen
2024-06-19 12:31:17 +02:00
parent 1d363e5a41
commit ce49354400

View File

@@ -24,6 +24,7 @@ import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -72,6 +73,8 @@ public class MockHttpServletResponse implements HttpServletResponse {
private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
private static final MediaType APPLICATION_PLUS_JSON = new MediaType("application", "*+json");
//---------------------------------------------------------------------
// ServletResponse properties
@@ -348,6 +351,10 @@ public class MockHttpServletResponse implements HttpServletResponse {
if (mediaType.getCharset() != null) {
setExplicitCharacterEncoding(mediaType.getCharset().name());
}
else if (mediaType.isCompatibleWith(MediaType.APPLICATION_JSON) ||
mediaType.isCompatibleWith(APPLICATION_PLUS_JSON)) {
this.characterEncoding = StandardCharsets.UTF_8.name();
}
}
catch (Exception ex) {
// Try to get charset value anyway