alibaba / alibaba/fastjson2

[FEATURE] 支持将单值解析为数组

Open
#1,810 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 请描述您的需求或者改进建议
```java
final JSONObject object = JSON.parseObject("{\"a\":1,\"b\":\"b\"}");
System.out.println(object.getJSONArray("a"));
System.out.println(object.getJSONArray("b"));
```
当前返回如下
```java
null

com.alibaba.fastjson2.JSONException: offset 1, character b, line 1, column 2, fastjson-version 2.0.39 b
at com.alibaba.fastjson2.reader.ObjectReaderImplList.readObject(ObjectReaderImplList.java:576)
at com.alibaba.fastjson2.JSONObject.getJSONArray(JSONObject.java:219)

```

### 请描述你建议的实现方案
期望能正确将1 和 字符串b解析为对应的数组格式

### 描述您考虑过的替代方案
fastjson1 支持上述的使用方式

#### 附加信息
当前使用的版本:
```xml

com.alibaba.fastjson2
fastjson2
2.0.39

```

Contributor guide

Open the contributing guide

Research direction

Start with JSONObject.getJSONArray and trace the failing path into ObjectReaderImplList.readObject, using the issue's numeric and string examples as the reproduction. Confirm the behavior against fastjson 1 if available, then add coverage showing that scalar values are converted to the expected array forms and that the relevant tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.