-
Notifications
You must be signed in to change notification settings - Fork 541
Closed
Labels
Milestone
Description
问题描述
含LinkedList对象的json反序列化不正确
环境信息
请填写以下信息:
- OS信息: mac
- JDK信息: Openjdk 1.8.0_312
- 版本信息:2.0.33
重现步骤
@Test
public void test() {
String json = "{\"testa\":[{\"name\":\"test\"}, {\"name\":\"test2\"}]}";
TestB testB1 = com.alibaba.fastjson2.JSON.parseObject(json, new com.alibaba.fastjson2.TypeReference<TestB>(){});
Assert.assertEquals(TestA.class.getName(), testB1.getTesta().get(0).getClass().getName());
}
@Data
public class TestB {
private LinkedList<TestA> testa;
}
@Data
public class TestA {
private String name;
}
期待的正确结果
期望是TestA的类型,实际是JSONObject
相关日志输出
java.lang.ClassCastException: class com.alibaba.fastjson2.JSONObject cannot be cast to class xxx.JsonTest$TestA (com.alibaba.fastjson2.JSONObject and xxx.JsonTest$TestA are in unnamed module of loader 'app')