1
测试代码
public static void main(String[] args) {
Policy policy = new Policy();
//2022-01-01 00:00:00
policy.setTime(new Date(1640966400000L));
String string = JSONObject.toJSONString(policy);
System.out.println(string);
policy = JSONObject.parseObject(string).toJavaObject(Policy.class);
string = JSONObject.toJSONString(policy);
System.out.println(string);
}
@Data
static class Policy{
@JSONField(format = "yyyyMMddHHmmss")
private Date time;
}
1.2.75及之前版本输出结果 {"time":"20220101000000"} {"time":"20220101000000"}
1.2.76及后面版本,包括最新1.2.83版本输出 {"time":"20220101000000"} {"time":"26101002064320"}
看着是反序列化的时候把时间格式yyyyMMddHHmmss当成了时间戳来反序列化