fastjson2
fastjson2 copied to clipboard
[BUG] JSON.toJSONString on Timestamp
问题描述
基于#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