问题:接口接收参数序列化日期localdate的时候报错了?
问题详情:
前端向服务一接口传参,服务一调用服务二接口时,服务二接口接收日期参数时报序列化错误。
代码示例:
前端传参:
`
public static resjson addxxx(@validated({addgroup.class}) @requestbody xxxdto xxxdto)
登录后复制
服务一调用服务二:
`
public static 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();登录后复制
}
服务二接口:
`public resjson getxxx(@requestbody xxxdto xxxdto)登录后复制
实体类字段:
`@notnull(message = "日期不能为空", groups = {addgroup.class})@JsonSerialize(using = LocalDateSerializer.class)@JsonDeserialize(using = LocalDateDeserializer.class)private LocalDate replaceDate;登录后复制
报错内容:
`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"])登录后复制
解决方案:
由于使用了jsr310规范,但序列化使用的是hutool工具包的序列化,导致序列化和反序列化的规范不一致。可以尝试使用fastjson来解决此问题。
替换如下代码:
`string json = json.tojsonstring(clazz);登录后复制
以上就是LocalDate日期序列化报错:服务间接口调用日期参数如何正确处理?的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/3152022.html