-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Closed
Copy link
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)
Description
I use getContentAsString() and mockMvc seems to return my Content as ISO 8859-1.
Before (with Spring Boot 2.1.8) it was proper UTF-8
When I add a produces to my Endpoint like @GetMapping(value = "/test", produces={"application/json; charset=UTF-8"}) it works as indented.
But I dont want todo this on our big project with tons of endpoints
Example:
@RestController
@RequestMapping("test")
public class TestClass {
@GetMapping
public List<String> test() {
return List.of("AEß");
}
}@RunWith(SpringRunner.class)
@SpringBootTest(classes = {Application.class})
@AutoConfigureMockMvc()
@ActiveProfiles("test")
@Transactional
public class TestClassTest {
@Autowired
private ObjectMapper objectMapper;
@Autowired
private MockMvc mvc;
@Test
public void test() throws Exception {
var mvcResult = mvc.perform(MockMvcRequestBuilders
.get("/test")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
assertEquals(List.of("AEß"), objectMapper.readValue(mvcResult.getResponse().getContentAsString(),
new TypeReference<List<String>>() {
}));
}
}Fails with:
java.lang.AssertionError:
Expected :[AEß]
Actual :[AE�]
Originally posted by @chrisaige in #23622 (comment)
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)