![在这里插入图片描述](https://img-blog.csdnimg.cn/122ae506912842058b7f09f154b02be0.png)
执行结果:
![在这里插入图片描述](https://img-blog.csdnimg.cn/08e74276e72e444ea1a584b82aa5d670.png)
以上可以看到productionDate
通过FastJson
序列化后变成时间戳。
如果我们想要转换成指定格式,尝试以下方法:
- 日期属性字段上添加
@JSONField
注解
@JSONField(format = "yyyy-MM-dd")
private Date productionDate;
- 使用
FastJson
内部函数toJSONStringWithDateFormat
替换toJSONString
JSONObject.toJSONStringWithDateFormat(goodsInfoDto, "yyyy-MM-dd", SerializerFeature.WriteDateUseDateFormat);
执行结果:
![在这里插入图片描述](https://img-blog.csdnimg.cn/655698ddc00547ac82f285d166ee0334.png)