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

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

Open
Cubeatz opened this issue Sep 20, 2024 · 1 comment
Labels
question Further information is requested

Comments

@Cubeatz
Copy link

Cubeatz commented Sep 20, 2024

请描述您的问题

询问有关本项目的使用和其他方面的相关问题。

我在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返回一致?

@Cubeatz Cubeatz added the question Further information is requested label Sep 20, 2024
@CodePlayer
Copy link
Contributor

先设置这个:

JSON.configWriterDateFormat("millis");

官方文档里也有说明哦:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants