alibaba / alibaba/fastjson2

针对 cn.hutool.core.date.DateTime 类型的属性反序列化时报错

Open
#3,297 0 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

### 问题描述
针对 cn.hutool.core.date.DateTime 类型的属性反序列化时报错

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

- OS信息: win10
- JDK信息: jdk17
- 版本信息:fastsjon2 目前最新

### 重现步骤
运行main

```java
public class DateTimeTest {

public static void main(String[] args) {
JSON.configReaderDateFormat("yyyy-MM-dd HH:mm:ss");
JSON.configWriterDateFormat("yyyy-MM-dd HH:mm:ss");

Bean bean1 = new Bean();
bean1.setDate3(new DateTime());

String jsonString = JSON.toJSONString(bean1);
System.out.println(jsonString);

Bean bean2 = JSON.parseObject(jsonString, Bean.class);
System.out.println(bean2);
}

@Data
static class Bean {
public DateTime date3;
}
}
```

### 期待的正确结果
反序列化对象正常

### 相关日志输出
{"date3":"2025-01-20 13:00:09"}
Exception in thread "main" com.alibaba.fastjson2.JSONException: expect ':', but 125, offset 10, character ", line 1, column 10, fastjson-version 2.0.54 {"date3":"2025-01-20 13:00:09"}
at com.alibaba.fastjson2.JSONReaderASCII.readFieldNameHashCode(JSONReaderASCII.java:390)
at com.alibaba.fastjson2.reader.ORG_2_11_DateTime.readObject(Unknown Source)
at com.alibaba.fastjson2.reader.ORG_1_1_Bean.readObject(Unknown Source)
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:864)
at com.guanwei.fastjson2.DateTimeTest.main(DateTimeTest.java:21)

Process finished with exit code 1

#### 附加信息

![Image](https://github.com/user-attachments/assets/dca60a11-7f81-458c-a95c-7caad028ee78)

Contributor guide

Open the contributing guide

Research direction

Start by running the DateTimeTest reproducer with JDK 17 and inspect the JSON.parseObject call and the stack trace through JSONReaderASCII.readFieldNameHashCode and the generated DateTime reader. The issue provides no source file or test location; done means the shown DateTime JSON deserializes into Bean successfully without the JSONException.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.