执行结果:
以上可以看到productionDate
通过FastJson
序列化后变成时间戳。
如果我们想要转换成指定格式,尝试以下方法:
- 日期属性字段上添加
@JSONField
注解
@JSONField(format = "yyyy-MM-dd")
private Date productionDate;
- 使用
FastJson
内部函数toJSONStringWithDateFormat
替换toJSONString
JSONObject.toJSONStringWithDateFormat(goodsInfoDto, "yyyy-MM-dd", SerializerFeature.WriteDateUseDateFormat);
执行结果: