alibaba / alibaba/fastjson2

[BUG]升级到fastjson2兼容包之后,原本的类型判断失效了

Open
#739 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

### 问题描述
*简要描述您碰到的问题。*

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

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

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

1. 使用 `com.alibaba.fastjson.JSONObject#getJSONArray` 及`com.alibaba.fastjson.JSON#parseObject(java.lang.String, com.alibaba.fastjson.TypeReference, com.alibaba.fastjson.parser.Feature...)`方法
2. 如果嵌套范型,如Optional,会编译不通过

这样的代码就变成错的了
他会把
```java
//可在此输入示例代码
Optional.ofNullable(event).filter(map -> HEART_BEAT_EVENT.equals(event))
.map(map -> JSON.parseObject(data, new TypeReference>() {
}));
```
识别为`Optional` 导致编译不通过,我只有像下面这样提前制定好类型,才可以链式调用
![image](https://user-images.githubusercontent.com/16757285/188808804-aac94472-01dd-4e5e-8b2a-a7fc4841a801.png)

以及
JSONArray.stream()原本也可以这样调用
```java
config.getJSONArray("uekms").stream().map(Object::toString).collect(Collectors.toList());
```
但是这么调用在2.0.12中编译不通过了已经;
![image](https://user-images.githubusercontent.com/16757285/188810039-b61535ab-4685-4acc-beae-c1198a35d57f.png)

现在我好像只能用
```java
config.getJSONArray("uekms").toJavaList(String.class);
```
### 期待的正确结果
我希望可以和之前一样,直接进行链式调用

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported generic-inference failures with JSONObject#getJSONArray, JSON#parseObject, and JSONArray#stream under Fastjson2 2.0.12. Compare these calls with the earlier behavior and verify that nested Optional and stream chains compile as expected when the compatibility issue is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.