This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
序列化LocalDateTime时,nanoOfSecond为0时,序列化格式不同 #1450
Labels
Comments
有问题么? |
我也没看懂,什么问题。 |
有问题,Jdk8DateCodec类中判断了,如果LocalDateTime类型,getNano() == 0的话是使用的 DEFFAULT_DATE_FORMAT 或者配置的format, 否则使用的是LocalDateTime自己的toString()方法。 |
还有这个问题在 1.2.11版中是不存在,因为Jdk8DateCodec.write 方法对所有类型都是调用 toString() 方法来序列化,但是为什么后续版本对LocalDateTime 类型进行了特殊判断,结果就造成了格式不一致的问题,求解? |
LocalDateTime localDateTime = LocalDateTime.of(2018, 8, 31, 15, 26, 37, 1);
String json = JSON.toJSONStringWithDateFormat(localDateTime, "yyyy-MM-dd HH:mm:ss");//2018-08-31T15:26:37.000000001
assertEquals("\"2018-08-31 15:26:37\"", json); 建议这样写 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
nanoOfSecond为0时:
LocalDateTime localDateTime = LocalDateTime.of(2018, 8, 31, 15, 26, 37, 0);
JSON.toJSONString(localDateTime);//2018-08-31 15:26:37
localDateTime.toString();//2018-08-31T15:26:37
nanoOfSecond不为0时:
LocalDateTime localDateTime = LocalDateTime.of(2018, 8, 31, 15, 26, 37, 1);
JSON.toJSONString(localDateTime).toString();//2018-08-31T15:26:37.000000001
localDateTime.toString();//2018-08-31T15:26:37.000000001
The text was updated successfully, but these errors were encountered: