alibaba / alibaba/fastjson2

[BUG]JSON.toJSONString(javaObject,SerializerFeature.WriteNonStringValueAsString) 兼容性问题

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

### 问题描述
*简要描述您碰到的问题。*
在fastjson2.0.26版本使用JSON.toJSONString(bb, SerializerFeature.MapSortField, SerializerFeature.SkipTransientField, SerializerFeature.WriteNonStringKeyAsString, SerializerFeature.WriteNonStringValueAsString);方式序列化Java对象。
泛型Long或Integer类型的List字段内部的元素也会被序列化为字符串。1.2.83则不会。属于兼容性问题。
![1](https://user-images.githubusercontent.com/41534037/230535572-0feab8f2-b82d-44a4-9ac9-638cfb107af8.png)2.0.26版本
![2](https://user-images.githubusercontent.com/41534037/230535590-2a31e4d3-8e27-4cd2-b564-5f58900de90b.png)1.2.83版本

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

- OS信息: windows 10 专业版 【21H1】 【19043.1766】 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz 2.59 GHz 16G
- JDK信息:jdk 1.8.0_221
- 版本信息:fastjson 2.0.26

### 重现步骤
*如何操作可以重现该问题:*

1.使用 JSON.toJSONString(bb, SerializerFeature.MapSortField, SerializerFeature.SkipTransientField, SerializerFeature.WriteNonStringKeyAsString, SerializerFeature.WriteNonStringValueAsString);方式序列化Java对象
2. 泛型Long或Integer类型的List字段内部的元素也会被序列化为字符串
```java
//可在此输入示例代码
```

### 期待的正确结果
*对您期望发生的结果进行清晰简洁的描述。*

### 相关日志输出
*请复制并粘贴任何相关的日志输出。*

#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported serialization with JSON.toJSONString and the listed SerializerFeature options, comparing fastjson 2.0.26 with 1.2.83. The issue is resolved when numeric elements in generic Long or Integer lists remain numbers while the requested non-string serialization behavior is preserved.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.