如何解决获取错误 org.springframework.http.converter.HttpMessageNotReadableException:无法构造 java.time.LocalDate 的实例
我正在尝试使用 oAuth2RestTemplate.getForEntity 进行 Rest Get 调用以提供服务,并希望将 json 回复映射到我的模型类之一中,但由于映射类使用本地日期(Java 8 概念),我收到以下错误除菌时:
org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not construct instance of java.time.LocalDate: no String-argument constructor/factory method to deserialize from String value ('1988-02-08')
at [来源:sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@96ce9eb2;行:1,
这是我的代码片段:
ResponseEntity<Some mapping class> response = this.oAuth2RestTemplate.getForEntity(this.ServiceUrl,Some mapping class.class,inputParameter);
我知道这是因为我的模型类将出生日期映射到 java 8 中引入的本地日期,而我的 oAuth2RestTemplate 不支持它。使用以下代码解决问题
ObjectMapper mapperObj = new ObjectMapper();
mapperObj.registerModule(new JavaTimeModule());
mapperObj.disable(WRITE_DATES_AS_TIMESTAMPS);
但在这种情况下,我需要以字符串形式获取服务响应,然后我需要对其进行转换。我需要 oAuth2RestTemplate 的解决方案。有人可以帮忙吗。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。