[BUG] 使用getJSONObject指定index获取元素时返回null
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
*简要描述您碰到的问题。*
在JSONObject嵌套了JsonArray的结构中,塞入Map.Entry类型时,无法通过getJSONObject获取指定元素
### 环境信息
*请填写以下信息:*
- OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
Microsoft Windows 10
- JDK信息: [e.g.:Openjdk 1.8.0_312]
Openjdk 1.8.0_422
- 版本信息:[e.g.:Fastjson2 2.x.x]
fastjson 2.0.56
### 重现步骤
*如何操作可以重现该问题:*
按如下结构构造数据,并获取对象
```java
Map map = new HashMap<>();
map.put("str", new float[] {1.0f, 1.0f, 1.0f, 1.0f, 1.0f});
JSONObject jo = new JSONObject();
JSONArray ja = new JSONArray();
ja.addAll(map.entrySet());
jo.put("content", ja);
JSONObject obj = jo.getJSONArray("content").getJSONObject(0);
System.out.println(obj.toJSONString());
```
### 期待的正确结果
*对您期望发生的结果进行清晰简洁的描述。*
使用 fastjson 1.2.83

使用 fastjson 2.0.56

### 相关日志输出
*请复制并粘贴任何相关的日志输出。*
#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*
如上代码中,向JSONArray ja中加入普通POJO无此问题,当前仅发现加入Map.Entry类型会触发此bug,不知道是否有别的类型也涉及
Contributor guide
Research direction
Run the supplied Java reproduction using JSONArray.addAll(map.entrySet()) and JSONArray.getJSONObject(0), comparing the behavior with the stated fastjson 1.2.83 result. Trace the conversion path for Map.Entry elements and add a regression test showing that the entry can be retrieved as a JSONObject without changing the behavior for ordinary POJOs.
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
- Clearly specified
- Newbie friendliness
- 35/100