Skip to content
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

Open
zyhui98 opened this issue Dec 16, 2024 · 1 comment
Open
Labels
bug Something isn't working
Milestone

Comments

@zyhui98
Copy link

zyhui98 commented Dec 16, 2024

问题描述

原因是升级JDK21之后,LocalDateTime默认精度从毫秒升级到纳秒了。

重现代码如下:

@Data
public class TestBean {
    private Date time;
}

public static void main(String[] args) throws Exception {
        String s = "{\"time\":\"2024-12-04T20:43:15.000000999\"}";
        System.out.println(JSONObject.parseObject(s, TestBean.class));
}

异常堆栈:
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)

@zyhui98 zyhui98 added the bug Something isn't working label Dec 16, 2024
@wenshao wenshao added this to the 2.0.54 milestone Dec 23, 2024
@wenshao
Copy link
Member

wenshao commented Dec 23, 2024

你用的是什么版本,我测试下来是支持的

wenshao added a commit that referenced this issue Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants