alibaba / alibaba/fastjson2

[BUG] 静态内部类序列化报错

Open
#1,879 0 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

### 问题描述
*简要描述您碰到的问题。*
公共静态内部类序列化报错,间隔频率出现
TestContext 类定义在TestResponse 类里面
```java
class TestResponse {
private TestContext testContext = null;

public TestContext getTestContext () {
return testContext;
}

public void setTestContext(TestContext testContext ) {
this.testContext = testContext;
}

public static class TestContext{

public TestContext() {
}


private String userInfo = "";


public String getUserInfo() {
return userInfo;
}

public void setUserInfo(String userInfo) {
this.userInfo = userInfo;
}

}
```

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

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

```java
Class returnType = TestResponse.class;
T result = JSON.parseObject(JSON.toJSONBytes(payload), returnType);
```

### 相关日志输出
*请复制并粘贴任何相关的日志输出。*
java.lang.NoClassDefFoundError: com/test/TestResponse$TestContext
at com.alibaba.fastjson2.reader.ORG_55_2_TestResponse.readObject(Unknown Source)
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:1365)
at java.base/java.util.concurrent.xecutors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.ClassNotFoundException: com.test.TestResponse$TestContext
... 16 common frames omitted

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported call using JSON.toJSONBytes(payload) and JSON.parseObject(..., TestResponse.class) with the nested static TestContext class. Inspect the generated ORG_55_2_TestResponse reader and the NoClassDefFoundError stack trace. Done means deserialization reliably succeeds without the missing TestResponse$TestContext class error.

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
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.