Skip to content

Commit

Permalink
Sync MockHttpServletResponse implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jun 19, 2024
1 parent 1d363e5 commit ce49354
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -348,6 +351,10 @@ public void setContentType(@Nullable String contentType) {
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
Expand Down

0 comments on commit ce49354

Please sign in to comment.