-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] 纳秒精度的时间字符串,反序列化成Date类型不兼容 #3210
Comments
你用的是什么版本,我测试下来是支持的 |
|
1.2.70也不行的。 |
请问,你是什么版本,我试试 |
import com.alibaba.fastjson2.JSONObject;
import lombok.Data;
import org.junit.jupiter.api.Test;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class Issue3210 {
@Data
public static class Bean {
private Date time;
}
@Test
public void test() {
String s = "{\"time\":\"2024-12-04T20:43:15.000000999\"}";
Bean bean = JSONObject.parseObject(s, Bean.class);
assertNotNull(bean.time);
}
} 当前的main分支的代码,我测试是好的 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题描述
原因是升级JDK21之后,LocalDateTime默认精度从毫秒升级到纳秒了。
重现代码如下:
异常堆栈:
Exception in thread "main" java.time.format.DateTimeParseException: Text '2024-12-04T20:43:15.000000999' could not be parsed, unparsed text found at index 19
at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2111)
at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:2010)
at java.base/java.time.LocalDateTime.parse(LocalDateTime.java:494)
at com.alibaba.fastjson2.reader.ObjectReaderImplDate.readDate(ObjectReaderImplDate.java:148)
at com.alibaba.fastjson2.reader.ObjectReaderImplDate.readObject(ObjectReaderImplDate.java:48)
at com.alibaba.fastjson2.reader.ORG_1_1_TestBean.readObject(Unknown Source)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:542)
The text was updated successfully, but these errors were encountered: