alibaba / alibaba/fastjson2

[BUG] 反序列化JSON字符串时报错

Open
#2,108 3 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

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

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

- 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.42]

### 重现步骤
*如何操作可以重现该问题:*
{
"Ref": "",
"Width": "",
"High": ""
}
jsonStr值如上:

User实体类如下:
![IMG_3970 jpeg](https://github.com/alibaba/fastjson2/assets/48472092/d92b0ad3-457c-4461-b014-da7b4a47bd35)

1. 使用 `xxx.xxx` 方法
JSONReader.Feature[] FASTJSON_DEFAULT_READER_FEATURES = {JSONReader.Feature.SupportSmartMatch, JSONReader.Feature.SupportArrayToBean, JSONReader.Feature.UseNativeObject, JSONReader.Feature.SupportClassForName,JSONReader.Feature.IgnoreSetNullValue,JSONReader.Feature.AllowUnQuotedFieldNames,JSONReader.Feature.IgnoreCheckClose,JSONReader.Feature.IgnoreAutoTypeNotMatch };
User user = JSON.parseObject(jsonStr, User.class, FASTJSON_DEFAULT_READER_FEATURES);
System.out.print(jsonObject);
3. 输入 `...` 数据
![IMG_3969 jpeg](https://github.com/alibaba/fastjson2/assets/48472092/8e5129a3-b18c-40f9-9efd-b74a5d686af1)

5. 出现 `...` 错误
![IMG_3968 jpeg](https://github.com/alibaba/fastjson2/assets/48472092/6669e2e2-ed4a-41d0-84c9-ad8548dbe0fe)

note: 把User实体类中的Double类型改为Integer类型,其他不变,再次执行,不报错。
```java
//可在此输入示例代码
```

### 期待的正确结果
*对您期望发生的结果进行清晰简洁的描述。*
反序列化正常,不报错

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

#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*

Contributor guide

Open the contributing guide

Research direction

Start with the reported JSON.parseObject(jsonStr, User.class, FASTJSON_DEFAULT_READER_FEATURES) call and compare the User field behavior when the numeric type is Double versus Integer. Reproduce the failure with the supplied JSON, then identify the reported error from the attached screenshot; done means the JSON deserializes without error while retaining the Double field type.

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
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.