Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue 3448 #3449

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {});
}
}