从1.2.75版本开始,java.sql.Date没有再单独处理,而是默认转换为java.util.Date,使用yyyy-MM-dd HH:mm:ss格式化,而不再格式化位yyyy-MM-dd。
@Data
private static class DemoBean{
private Date date;
private Time time;
}
@Test
public void test(){
DemoBean demoBean = new DemoBean();
demoBean.date = Date.valueOf("2022-06-01");
demoBean.time = Time.valueOf("13:13:13");
String content = JSON.toJSONString(demoBean, SerializerFeature.WriteDateUseDateFormat);
System.out.println(content);
}
1.2.75及其以上输出:{"date":"2022-06-01 00:00:00","time":"13:13:13"} 1.2.74及其以下输出:{"date":"2022-06-01","time":"13:13:13"}
可能涉及类: com.alibaba.fastjson.serializer.DateCodec com.alibaba.fastjson2.writer.ObjectWriterImplDate