
问题:接口接收参数序列化日期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
报错内容:
`
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);










