Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3826 from hnyyghk/fix-generic-field-deserialize
Fix generic field deserialize, issue #3810
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/test/java/com/alibaba/json/bvt/issue_3800/Issue3810.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |