alibaba / alibaba/fastjson2

java.sql.Timestamp序列化丢失类型

Open
#2,706 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

### 问题描述
java.sql.Timestamp类型序列化时,使用JSONWriter.Feature.WriteClassName依然会丢失类型,反序列化后认为是字符串,但“java.util.Date"不会,从序列化的字符串来看,“java.util.Date"有特殊处理,java.sql.Timestamp没有?

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

- OS信息: Mac
- JDK信息:jdk17
- 版本信息:Fastjson2 2.0.51

### 重现步骤

```java
String timestampOut = JSON.toJSONString(new java.sql.Timestamp(new Date().getTime()),
JSONWriter.Feature.WriteClassName);
System.out.println(JSON.parseObject(timestampOut, Object.class).getClass());

String dateOut = JSON.toJSONString(new Date(), JSONWriter.Feature.WriteClassName);
System.out.println(JSON.parseObject(dateOut, Object.class).getClass());
```

### 期待的正确结果
timestampOut的输出为“class java.sql.Timestamp”,现在的输出的是“class java.lang.String”

Contributor guide

Open the contributing guide

Research direction

Start with the supplied JSON.toJSONString and JSON.parseObject reproduction using java.sql.Timestamp, java.util.Date, and JSONWriter.Feature.WriteClassName. Compare the serialization and deserialization paths for both types; done means the Timestamp example reports class java.sql.Timestamp while the Date example continues to work.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.