[BUG]公元前时间反序列化出错
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
公元前时间反序列化出错
### 环境信息
*请填写以下信息:*
- OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
- JDK信息: [e.g.:Openjdk 1.8.0_312]
- 版本信息:[e.g.:Fastjson2 2.0.60]
### 重现步骤
LocalDateTime time=LocalDateTime.of(0,1,1,0,0,0,0).minusHours(8);
JSONObject bean=new JSONObject().fluentPut("time",time);
String s = bean.toJSONString();
System.out.println(s);
System.out.println(JSON.parseObject(s).getLocalDateTime("time"));
### 期待的正确结果
不抛出异常
### 相关日志输出
Exception in thread "main" com.alibaba.fastjson2.JSONException: read LocalDateTime error -0001-12-31 16:00:00, offset 22, character , line 1, column 22, fastjson-version 2.0.60 "-0001-12-31 16:00:00"
at com.alibaba.fastjson2.JSONReader.readLocalDateTime(JSONReader.java:2506)
at com.alibaba.fastjson2.reader.ObjectReaderImplLocalDateTime.readObject(ObjectReaderImplLocalDateTime.java:64)
at com.alibaba.fastjson2.util.TypeUtils.cast(TypeUtils.java:1522)
at com.alibaba.fastjson2.util.TypeUtils.cast(TypeUtils.java:1426)
at com.alibaba.fastjson2.JSONObject.getLocalDateTime(JSONObject.java:1087)
at com.alibaba.fastjson2.JSONObject.getLocalDateTime(JSONObject.java:1072)
#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*
Contributor guide
Research direction
Reproduce the example with LocalDateTime.of(0,1,1,0,0,0,0).minusHours(8), then start in JSONReader.java at readLocalDateTime and follow the ObjectReaderImplLocalDateTime path shown in the stack trace. Add a regression test for the BCE value and confirm JSON.parseObject(s).getLocalDateTime("time") no longer throws.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100