alibaba / alibaba/fastjson2

[QUESTION]fastjson 1.2.83->2.0.53 含有Date类型的JSONObject调用toString()方法怎么可以保持一致

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

Description

### 请描述您的问题
*询问有关本项目的使用和其他方面的相关问题。*

我在fastjson的1.2.83版本和2.0.53分别执行了以下代码:

```
@Getter
@Setter
public class Test{
private Date lastLoginTime;
}
```

```
@SneakyThrows
public static void main(String[] args) {
JSONObject results = new JSONObject();
Test test = new Test();
test.setLastLoginTime(DateUtils.parseDate("2024-09-20 14:54:35","yyyy-MM-dd HH:mm:ss"));
results.put("test", test);
System.out.println(results.toString());
}
```

fastjson1.x的返回:
`{"test":{"lastLoginTime":1726815275000}}`

fastjson2.x的返回:
`{"test":{"lastLoginTime":"2024-09-20 14:54:35"}}`

请问上述返回,我要怎么做才能和fastjson1.x返回一致?

Contributor guide

Open the contributing guide

Research direction

The reproduction uses the Test class, DateUtils.parseDate, JSONObject.put, and JSONObject.toString() across fastjson 1.2.83 and 2.0.53. Start by checking the date serialization behavior and configuration options for both versions. Done means documenting or verifying how fastjson2 can produce the epoch-millisecond output shown for fastjson 1.x.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.