I wrote simple controller:
@RestController
public class TestController {
@GetMapping("/api")
public Map<String, String> simpleTest() {
// here is the text with special characters, all in UTF-8
return Collections.singletonMap("test", "Příliš žluťoučký kůň úpěl ďábelské ódy");
}
}
Also very simple tutorial-like test:
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}
@Test
public void test() throws Exception {
this.mockMvc.perform(get("/api"))
.andDo(print())
.andExpect(jsonPath("$.test").value("Příliš žluťoučký kůň úpěl ďábelské ódy"));
}
The test fails in version 5.2.0.M3 now. Test passes in the previous milestone version 5.2.0.M2 and earlier versions.
The issue is somehow related to deprecation of org.springframework.http.MediaType#APPLICATION_JSON_UTF8_VALUE.
Of course it is possible to fix the test by adding accept but I rather do not do that, because APPLICATION_JSON_UTF8_VALUE is deprecated now.
.accept(MediaType.APPLICATION_JSON_UTF8_VALUE)
I have also prepared simple maven project to simulate the problem.
springutf8.zip
It seems to me, that MockMvc client does not handle UTF-8 characters well, like other modern browsers.
I wrote simple controller:
Also very simple tutorial-like test:
The test fails in version 5.2.0.M3 now. Test passes in the previous milestone version 5.2.0.M2 and earlier versions.
The issue is somehow related to deprecation of
org.springframework.http.MediaType#APPLICATION_JSON_UTF8_VALUE.Of course it is possible to fix the test by adding accept but I rather do not do that, because
APPLICATION_JSON_UTF8_VALUEis deprecated now.I have also prepared simple maven project to simulate the problem.
springutf8.zip
It seems to me, that
MockMvcclient does not handle UTF-8 characters well, like other modern browsers.