Я использую Junit и Mock MVC для некоторых интеграционных тестов ... один из наших тестов работал, как и ожидалось, пока мы просто не обновились до Spring Boot 2.2.5.
mockMvc.perform(
post("/experiments")
.contentType(MediaType.APPLICATION_JSON)
.content(requestPayload)) // requestPayload is a purposefully invalid JSON string with a missing bracket
.andDo(print())
.andExpect(status().isBadRequest());
Не может fini sh тест, потому что обновленная версия Spring выдает ошибку перед завершением запроса из-за неверного JSON (согласно приведенной ниже ошибке). Есть ли способ заставить насмешку MVC ожидать плохого JSON в моем тесте?
Request processing failed; nested exception is org.springframework.http.converter.HttpMessageConversionException: JSON conversion problem: Unexpected character ('{' (code 123)): was expecting double-quote to start field name; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Unexpected character ('{' (code 123)): was expecting double-quote to start field name
at [Source: (PushbackInputStream); line: 1, column: 232] (through reference chain: com.allstate.d3.sh.commons.rest.ExperimentDetail["buckets"]->java.util.ArrayList[0])
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.http.converter.HttpMessageConversionException: JSON conversion problem: Unexpected character ('{' (code 123)): was expecting double-quote to start field name; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Unexpected character ('{' (code 123)): was expecting double-quote to start field name
at [Source: (PushbackInputStream); line: 1, column: 232] (through reference chain: com.allstate.d3.sh.commons.rest.ExperimentDetail["buckets"]->java.util.ArrayList[0])
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)