我正在使用 MockMvc 编写集成测试,并希望接收作为对象的响应,以便对其进行断言。
线路
AuthenticationResponse authenticationResponse = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), AuthenticationResponse.class);
抛出错误:
Unable to make field private final java.time.ZoneOffset java.time.ZonedDateTime.offset accessible: module java.base does not "opens java.time" to unnamed module
我的应用程序通常使用时没有错误。测试中仅解析它时出现错误。
搜索 Stackoverflow 没有帮助,因为没有类似的问题。
您需要使用以下标志运行测试:
java ... --add-opens java.base/java.time=ALL-UNNAMED
另请参阅:https://github.com/spring-projects/spring-data-mongodb/issues/3893