首页 > 其他分享 >FastJson序列化后Date日期类型变成时间戳

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

时间:2023-03-20 14:23:16浏览次数:35  
标签:FastJson JSONField dd yyyy Date 序列化

日志

在这里插入图片描述

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

解决

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

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

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

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

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

标签:FastJson,JSONField,dd,yyyy,Date,序列化
From: https://www.cnblogs.com/iqiuq/p/17236128.html

相关文章