JSONStreamReader 反序列化失败[BUG]
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
*简要描述您碰到的问题。*
反序列化对象失败,出现:
com.alibaba.fastjson2.JSONException: Illegal syntax: ``, offset 1, character , line 1, column 2, fastjson-version 2.0.40 {
at com.alibaba.fastjson2.JSONReaderUTF8.nextIfObjectEnd(JSONReaderUTF8.java:548)
at com.alibaba.fastjson2.reader.ObjectReaderImplObject.readObject(ObjectReaderImplObject.java:159)
at com.alibaba.fastjson2.JSONReader.read(JSONReader.java:2253)
at com.alibaba.fastjson2.JSONReader.readAny(JSONReader.java:2404)
at com.alibaba.fastjson2.stream.JSONStreamReaderUTF8.readLineObject(JSONStreamReaderUTF8.java:175)
at DocJsonTest.StringConvertDocJsonTest(DocJsonTest.java:123)
### 环境信息
*请填写以下信息:*
- OS信息: mac Darwin U-W1HDWHKF-0225.local 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:39:46 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6020 arm64
- JDK信息:java version "1.8.0_291"
- 版本信息:Fastjson2 2.0.40
### 重现步骤
*如何操作可以重现该问题:*
1. 使用 `JSONStreamReader reader.readLineObject ` 方法
2. 输入文件数据
例如json:
```
{
"requestId": "8961167a73fa40e38feda862cd57b311",
"success": true,
"code": 200,
"msg": "成功"
}
```
3. 出现 `com.alibaba.fastjson2.JSONException` 错误
```java
String path = "/Users/sanchuan/Downloads/1.json";
try (FileInputStream fis = new FileInputStream(path)) {
JSONStreamReader reader = JSONStreamReader.of(fis);
Object object;
while ((object = reader.readLineObject()) != null) {
JSONObject jsonObject = (JSONObject)object;
jsonObject.size();
}
}
```
### 期待的正确结果
正确的反序列化成JSONObject
Contributor guide
Research direction
Start at JSONStreamReaderUTF8.readLineObject and the JSONReaderUTF8 stack frames, then reproduce the supplied FileInputStream example with the JSON data shown. Determine why the reader encounters the \u001a character and verify that readLineObject returns a JSONObject successfully for the input.
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
- 35/100