Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3449 from pymBupt/issue/#3448
Browse files Browse the repository at this point in the history
fix issue 3448
  • Loading branch information
wenshao authored Sep 18, 2020
2 parents 2d0d805 + 590140a commit e60b9ac
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/com/alibaba/fastjson/TypeReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private Type handlerParameterizedType(ParameterizedType type, Type[] actualTypeA

// 如果有多层泛型且该泛型已经注明实现的情况下,判断该泛型下一层是否还有泛型
if(argTypes[i] instanceof ParameterizedType) {
return handlerParameterizedType((ParameterizedType) argTypes[i], actualTypeArguments, actualIndex);
argTypes[i] = handlerParameterizedType((ParameterizedType) argTypes[i], actualTypeArguments, actualIndex);
}
}

Expand Down
43 changes: 43 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_3300/Issue3448.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.alibaba.json.bvt.issue_3300;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import junit.framework.TestCase;
import org.junit.Test;

/**
* @author yumin.pym
*/
public class Issue3448 extends TestCase {
public static class SelfTypeReference<T> {

}

@Test
public void test() {
List<Map<String, List<String>>> list = new ArrayList<>(4);
list.add(Collections.singletonMap("key1", Collections.singletonList("item")));
String text = JSON.toJSONString(list);
System.out.println("text = " + text);

List<Map<String, List<String>>> result = parseObject(text,
new SelfTypeReference<Map<String, List<String>>>() {});
System.out.println("result = " + result);
TestCase.assertTrue(result.get(0) instanceof Map);
TestCase.assertTrue(result.get(0).get("key1").get(0) instanceof String);
}

public <T> List<T> parseObject(String text, SelfTypeReference<T> selfTypeReference) {
Type genericSuperclass = selfTypeReference.getClass().getGenericSuperclass();
Type[] actualTypeArguments = ((ParameterizedType)genericSuperclass).getActualTypeArguments();
return JSON.parseObject(text, new TypeReference<List<T>>(actualTypeArguments) {});
}
}

0 comments on commit e60b9ac

Please sign in to comment.