Skip to content

Commit

Permalink
Fix generic field deserialize, issue #3810
Browse files Browse the repository at this point in the history
  • Loading branch information
hnyyghk committed Jun 30, 2021
1 parent 14a95cc commit bd25316
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void parseField(DefaultJSONParser parser, Object object, Type objectType,
}
if (fieldType != objectType) {
fieldType = FieldInfo.getFieldType(this.clazz, objectType, fieldType);
if (fieldValueDeserilizer == null) {
if (fieldValueDeserilizer instanceof JavaObjectDeserializer) {
fieldValueDeserilizer = parser.getConfig().getDeserializer(fieldType);
}
}
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_3800/Issue3810.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.alibaba.json.bvt.issue_3800;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.util.ParameterizedTypeImpl;
import junit.framework.TestCase;
import lombok.Data;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
* https://github.com/alibaba/fastjson/issues/3810
*
* @author hnyyghk
* @date 2021/06/30 18:40
*/
public class Issue3810 extends TestCase {
@Data
static class TestA<T> {
T a;
}

@Data
static class TestB {
String b;
}

private final static String json = "{\"a\":[{\"b\":\"b\"}]}";

public void test_for_issue() throws Exception {
ParameterizedTypeImpl inner = new ParameterizedTypeImpl(new Type[]{TestB.class}, List.class, List.class);
ParameterizedTypeImpl outer = new ParameterizedTypeImpl(new Type[]{inner}, TestA.class, TestA.class);
JSONObject jo = JSONObject.parseObject(json);
TestA<List<?>> ret = jo.toJavaObject(outer);

assertEquals(ArrayList.class.getName(), ret.getA().getClass().getName());
assertEquals(TestB.class.getName(), ret.getA().get(0).getClass().getName());
}
}

0 comments on commit bd25316

Please sign in to comment.