[BUG] Dubbo 使用 Fastjson2.0.57 版本时提示 not support none-Serializable
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
如下代码所示,Dubbo 使用 Fastjson 2.0.57 版本时提示报错:not support none-Serializable。
使用 Fastjson 2.0.56 及之前版本则一切正常。
### 环境信息
*请填写以下信息:*
- OS信息: Windows 10
- JDK信息:OpenJDK 17.0.14
- 版本信息:Fastjson 2.0.57
### 重现步骤
```java
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
static class Message implements Serializable {
T msg;
}
@Test
public void test() {
Message obj = new Message<>("Hello");
byte[] bytes = JSONB.toBytes(obj, JSONWriter.Feature.WriteClassName,
JSONWriter.Feature.FieldBased,
JSONWriter.Feature.ErrorOnNoneSerializable,
JSONWriter.Feature.ReferenceDetection,
JSONWriter.Feature.WriteNulls,
JSONWriter.Feature.NotWriteDefaultValue,
JSONWriter.Feature.NotWriteHashMapArrayListClassName,
JSONWriter.Feature.WriteNameAsSymbol);
ContextAutoTypeBeforeHandler handler = new ContextAutoTypeBeforeHandler(true, obj.getClass());
Object result = JSONB.parseObject(bytes, obj.getClass(), handler,
JSONReader.Feature.UseDefaultConstructorAsPossible,
JSONReader.Feature.ErrorOnNoneSerializable,
JSONReader.Feature.IgnoreAutoTypeNotMatch,
JSONReader.Feature.UseNativeObject,
JSONReader.Feature.FieldBased);
}
```
### 期待的正确结果
一切正常
### 相关日志输出
```
com.alibaba.fastjson2.JSONException: not support none-Serializable
at com.alibaba.fastjson2.reader.FieldReaderObject.readFieldValueJSONB(FieldReaderObject.java:185)
at com.alibaba.fastjson2.reader.ObjectReaderAdapter.readFieldValue(ObjectReaderAdapter.java:506)
at com.alibaba.fastjson2.reader.ORG_1_1_Message.readJSONBObject(Unknown Source)
at com.alibaba.fastjson2.JSONB.parseObject(JSONB.java:569)
```
#### 附加信息
如果将泛型 `` 声明改为 ``,就能够恢复正常。
Contributor guide
Research direction
Start with the failing stack trace in FieldReaderObject.java and follow the calls through ObjectReaderAdapter.java and JSONB.parseObject. Reproduce the provided Message case with Fastjson 2.0.57 and the listed JSONB features, then verify that an unconstrained generic T works as it did in 2.0.56 while the bounded T extends Serializable case remains working.
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
- Mostly clear
- Newbie friendliness
- 45/100