获取错误org.springframework.http.converter.httpmessagenoteradableexception:can not 构造java.time.localdate的示例

wko9yo5t  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(226)

我正在尝试使用oauth2resttemplate.getforentity执行rest get调用以提供服务,并期望json replyMap到我的一个模型类中,但是由于Map类使用本地日期(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')

[来源:sun.net。www.protocol.http.httpurlconnection$httpinputstream@96ce9eb2; 行:1,
以下是我的代码片段:

ResponseEntity<Some mapping class> response = this.oAuth2RestTemplate.getForEntity(this.ServiceUrl, Some mapping class.class, inputParameter);

我知道这是因为我的模型类将出生日期Map为java8中引入的本地日期,而oauth2restemplate不支持它。使用下面的代码可以解决这个问题

ObjectMapper mapperObj = new ObjectMapper();
mapperObj.registerModule(new JavaTimeModule());
mapperObj.disable(WRITE_DATES_AS_TIMESTAMPS);

但在这种情况下,我需要以字符串形式获取服务响应,然后需要转换它。我需要一个oauth2resttemplate的解决方案。有人能帮忙吗。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题