
问题:接口接收参数序列化日期localdate的时候报错了?
问题详情:
前端向服务一接口传参,服务一调用服务二接口时,服务二接口接收日期参数时报序列化错误。
代码示例:
服务一调用服务二:
 `<div class="code-block"><pre>public static <t> string sendpost(t clazz, string url) {
  jsonobject jsonobject = jsonutil.parseobj(clazz);
  httpservletrequest request = servletutils.getrequest();
  string authorization = request.getheader(constants.authorization);
  return httputil.createpost(url)
          .header(constants.authorization, authorization)
          .body(jsonobject.tostring()).timeout(20000).execute().body();}</pre> </div>
实体类字段:
`<div class="code-block"><pre>@notnull(message = "日期不能为空", groups = {addgroup.class})
@JsonSerialize(using = LocalDateSerializer.class) @JsonDeserialize(using = LocalDateDeserializer.class) private LocalDate<T> replaceDate;</code></pre> </div>
报错内容:
`<div class="code-block"><pre>org.springframework.http.converter.httpmessagenotreadableexception: json parse error: invalid value for year (valid values -999999999 - 999999999): 4665973755; nested exception is com.fasterxml.jackson.databind.jsonmappingexception: invalid value for year (valid values -999999999 - 999999999): 4665973755 (through reference chain: com.xxx.xxxdto["replacedate"])</pre> </div> 
解决方案:
由于使用了jsr310规范,但序列化使用的是hutool工具包的序列化,导致序列化和反序列化的规范不一致。可以尝试使用fastjson来解决此问题。
替换如下代码:
`<div class="code-block"><pre>string json = json.tojsonstring(clazz);</pre> </div>
以上就是LocalDate日期序列化报错:服务间接口调用日期参数如何正确处理?的详细内容,更多请关注php中文网其它相关文章!
                        
                        每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号