alibaba / alibaba/fastjson2

[BUG] java.lang.ClassCastException

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

### 问题描述
*简要描述您碰到的问题。*
对象存在list情况下出现 失败;没有则正常

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

- OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
linux /windows
- JDK信息: [e.g.:Openjdk 1.8.0_312]
- 1.8.311
- 版本信息:[e.g.:Fastjson2 2.x.x]
2.0.52

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

1. 使用 `xxx.xxx` 方法
JSON.parseObject(text, clazz);
3. 输入 `...` 数据

@Data
public class XXData implements Serializable {
private static final long serialVersionUID = 1L;

private String code;// 状态码
private String message;// 状态描述
private Boolean success;
private Record data;
}

@Data
public class Record implements Serializable {
private static final long serialVersionUID = 1L;

private Integer total;// 总数
private Integer size;// 每页条数
private Integer current;// 当前页数

private List records;
}

5. 出现 `...` 错误
6.
捕获异常:java.lang.ClassCastException: com.xx.XXData cannot be cast to com.xx.XXData

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure through JSON.parseObject(text, clazz) with the XXData, Record, and EntityData classes shown in the report, using fastjson2 2.0.52 on JDK 1.8.311. Done means the nested object containing a List no longer produces the reported ClassCastException.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.