-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Spring default characterEncoding #26171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The characterEncoding in |
When the response from a JSON endpoint contains UTF-8 characters (ěščřžýá), then the MockHttpServletResponse will consider them as ISO-8859-1 and the these characters will be received broken. If the tests perform assertEquals on such strings, they will fail. |
So you're probably doing this? assertEquals("...", response.getContentAsString()); but should be: assertEquals("...", response.getContentAsString(StandardCharsets.UTF_8)); |
The problem is that until having original again:
it is just strange to migrate to version without |
Right but the change reflects the fact that it is now up to clients to be compliant and interpret this correctly. In MockMvc we automatically interpret JSON as UTF-8 but in this case you're reading directly from the response and it is up to your tests to do that. It is too low level a place for us to start adding functionality like that. |
Ok, thanks. |
Since Spring 5.2 MediaType.APPLICATION_JSON_UTF8 is @deprecated as described within MediaType class:
So basically everyone should be using
MediaType.APPLICATION_JSON_VALUE
without (UTF8 information) instead. This is unfortunately in conflict withMockHttpServletResponse
:So even thought UTF8 is expected by default, the testing environment is in violation with aboves:
The tests which explicitly don't override this encoding will fail.
The text was updated successfully, but these errors were encountered: