问题描述
我正在尝试使用 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 (将#修改为@)