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

[BUG] JSON.toJSONString on Timestamp #2553

Closed
Cooper-Zhong opened this issue May 10, 2024 · 1 comment
Closed

[BUG] JSON.toJSONString on Timestamp #2553

Cooper-Zhong opened this issue May 10, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Cooper-Zhong
Copy link
Contributor

问题描述

基于#2460,fastjson和fastjson2序列化timestamp格式不统一

环境信息

  • OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
  • JDK信息: [Openjdk 17.0.6]
  • 版本信息:[Fastjson 2.0.49/2.0.50-SNAPSHOT]

重现步骤

import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Test;
import java.sql.Timestamp;
import java.time.Instant;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class MutatedIssue2460_351 {
    @Test
    public void mutatedTest() {
        // Create a Timestamp object with different epoch milliseconds
        Timestamp ts = Timestamp.from(Instant.ofEpochMilli(1713494836124L));
        String str1 = JSON.toJSONString(ts);
        String str2 = com.alibaba.fastjson.JSON.toJSONString(ts);
        assertEquals(str1, str2);
    }
}

期待的正确结果

统一数据格式

相关日志输出

Expected :"2024-04-19 10:47:16.124"
Actual :1713494836124

@Cooper-Zhong Cooper-Zhong added the bug Something isn't working label May 10, 2024
@wenshao
Copy link
Member

wenshao commented May 10, 2024

fastjson1和fastjson2在这个的行为不一致设计就是这样的,这不是bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants