alibaba / alibaba/fastjson2

[BUG]kotlin的writeBytes写入异常

Open
#3,963 9 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

### 问题描述
*简要描述您碰到的问题。*
使用JSONObject#toJSONBBytes时会出现编码错误,文件是UTF-8,但他使用别的编码类型了

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

- OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
- JDK信息: [e.g.:Openjdk 21.0.4]
- 版本信息:[e.g.:Fastjson2 2.0.60]

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

1. new JSONObject()后put内容,然后使用toJSONBBytes变成byteArray,最后kotlin的writeBytes扩展方法写入
```kotlin
val json = JSONObject()
json["text"] = "test"
File("text.json").writeBytes(JSON.toJSONBytes(json))
```

### 期待的正确结果
*对您期望发生的结果进行清晰简洁的描述。*
正常来说应该是和JSON.toJSONBytes一样

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

#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*
写入后冒号后并没有空格,有这个规则吗

Contributor guide

Open the contributing guide

Research direction

The report names JSONObject, JSON.toJSONBytes, JSONB output, and Kotlin File.writeBytes; start by comparing the produced bytes and resulting text for the supplied example. Reproduce the issue with the snippet and the missing environment details, then establish whether the encoding and colon spacing discrepancy is in Fastjson2 output or Kotlin file writing.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
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.