FastJson序列化后Date日期类型变成时间戳

日志

在这里插入图片描述

执行结果:
在这里插入图片描述
以上可以看到productionDate通过FastJson序列化后变成时间戳了

解决

方式一: 日期属性字段上添加@JSONField注解

@JSONField(format = "yyyy-MM-dd")
private Date productionDate;

方式二: 使用FastJson内部函数toJSONStringWithDateFormat替换toJSONString

JSONObject.toJSONStringWithDateFormat(goodsInfoDto, "yyyy-MM-dd", SerializerFeature.WriteDateUseDateFormat);

执行结果:
在这里插入图片描述

posted @ 2023-03-20 14:13  少爷晚安。  阅读(719)  评论(0编辑  收藏  举报