alibaba / alibaba/fastjson2

[BUG]

Open
#1,468 1 comment 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

### 问题描述
*对包含ascii码特殊字符比如换行 进行序列化,未执行转义到\n,导致系统处理出现bug,fastjson2文档中未找到序列化转义的feature配置,而fastjson1是默认支持序列化转义的*

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

- OS信息: CentOS 8.4.2105 4Core 3.10GHz 16 GB
- JDK信息:Openjdk 1.8.0_312
- 版本信息:Fastjson2 2.x.x

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

1. 使用 ` static String toJSONString(Object object, String format, JSONWriter.Feature... features) ` 方法
2. 输入 ` ` 数据
3. 出现 `...` 错误
```java
//可在此输入示例代码
TicketInfo ticketInfo = new TicketInfo();
ticketInfo.setPassengerName("我\n爱\n你" );
JSON.toJSONString(ticketInfo);

### 期待的正确结果
*{"passengerName":"我\n爱\n你"}*

### 相关日志输出
*{"passengerName":"我

你"}*

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

Contributor guide

Open the contributing guide

Research direction

Start with the Java JSON.toJSONString(Object) entry point and the JSONWriter.Feature options mentioned in the report. Reproduce the TicketInfo example with newline characters, then inspect the serialization path and existing tests for string escaping. Done means control characters are escaped in the serialized JSON as expected and the regression is covered by a test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design
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.