When MediaType.APPLICATION_JSON_UTF8 was deprecated, the content type of JSON that gets sent from a @RestController changed to application/json (without charset).
This breaks MockMvc tests that use .andExpect(content().json()). Here is a sample test:
@Test
public void returnsTheExpectedResponse() throws Exception {
mockMvc.perform(get("/"))
.andExpect(status().isOk())
.andExpect(content().json("{\"name\":\"Jürgen\"}"));
}
The test runs fine with Spring 5.1.9 but fails with Spring 5.2.0.RC2
java.lang.AssertionError: name
Expected: Jürgen
got: Jürgen
You can find a sample Spring Boot project to reproduce the problem at https://github.com/sgybas/mockmvc-json-utf8
There was a similar issue for jsonPath() (#23219).
When
MediaType.APPLICATION_JSON_UTF8was deprecated, the content type of JSON that gets sent from a@RestControllerchanged toapplication/json(without charset).This breaks
MockMvctests that use.andExpect(content().json()). Here is a sample test:The test runs fine with Spring 5.1.9 but fails with Spring 5.2.0.RC2
You can find a sample Spring Boot project to reproduce the problem at https://github.com/sgybas/mockmvc-json-utf8
There was a similar issue for
jsonPath()(#23219).