alibaba / alibaba/fastjson2

[BUG] UTC时间格式反序列化至LocalDateTime时相同的时间有不同的输出结果

Open
#2,831 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 问题描述
当转换UTC时间格式的字符到LocalDateTime时,未得到预期的值

### 环境信息
*请填写以下信息:*

- OS信息: [windows 10]
- JDK信息: [Openjdk 11]
- 版本信息:[Fastjson2 2.0.52]

### 重现步骤
```java
@Data
static class TestLocalDateTime{
private LocalDateTime localDateTime;
}
public static void main(String[] args) {
TestLocalDateTime testLocalDateTime1 = JSON.parseObject("{\"localDateTime\":\"2024-07-28T00:00:30Z\"}", TestLocalDateTime.class);
TestLocalDateTime testLocalDateTime2 = JSON.parseObject("{\"localDateTime\":\"2024-07-28T00:00:30.000Z\"}", TestLocalDateTime.class);
System.out.println(testLocalDateTime1);
System.out.println(testLocalDateTime2);
}
```

### 期待的正确结果
Fastjson2Demo.TestLocalDateTime(localDateTime=2024-07-28T08:00:30)
Fastjson2Demo.TestLocalDateTime(localDateTime=2024-07-28T08:00:30)

### 相关日志输出
Connected to the target VM, address: '127.0.0.1:56831', transport: 'socket'
00:49:55.982 [main] DEBUG reactor.util.Loggers$LoggerFactory - Using Slf4j logging framework
00:49:55.990 [main] DEBUG reactor.core.publisher.Hooks - Enabling stacktrace debugging via onOperatorDebug
Fastjson2Demo.TestLocalDateTime(localDateTime=2024-07-28T00:00:30)
Fastjson2Demo.TestLocalDateTime(localDateTime=2024-07-28T08:00:30)
Disconnected from the target VM, address: '127.0.0.1:56831', transport: 'socket'

Process finished with exit code 0

#### 附加信息
![image](https://github.com/user-attachments/assets/8c1f4ce4-5eb8-4d19-9b0a-c15b785d6de4)

Contributor guide

Open the contributing guide

Research direction

Start with the JSON.parseObject entry point and run the provided Java reproduction using both UTC strings on JDK 11 and Fastjson2 2.0.52. Trace the LocalDateTime deserialization path and add a regression test covering both inputs; done means both produce the expected local time consistently.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.