ObjectMapper 不会将 JSON 的字符串映射到 ZonedDateTime

问题描述 投票:0回答:1

我正在使用 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 没有帮助,因为没有类似的问题。

spring-boot jackson spring-test spring-test-mvc
1个回答
0
投票

您需要使用以下标志运行测试:

java ... --add-opens java.base/java.time=ALL-UNNAMED

另请参阅:https://github.com/spring-projects/spring-data-mongodb/issues/3893

© www.soinside.com 2019 - 2024. All rights reserved.