mirror of
https://github.com/alibaba/fastjson.git
synced 2026-10-28 13:50:47 +08:00
bug fixed for WildcardType extends Generic Type. issue #998
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package com.alibaba.fastjson.parser;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -28,7 +25,15 @@ class ListTypeFieldDeserializer extends FieldDeserializer {
|
||||
Type fieldType = fieldInfo.fieldType;
|
||||
Class<?> fieldClass= fieldInfo.fieldClass;
|
||||
if (fieldType instanceof ParameterizedType) {
|
||||
this.itemType = ((ParameterizedType) fieldType).getActualTypeArguments()[0];
|
||||
Type argType = ((ParameterizedType) fieldInfo.fieldType).getActualTypeArguments()[0];
|
||||
if (argType instanceof WildcardType) {
|
||||
WildcardType wildcardType = (WildcardType) argType;
|
||||
Type[] upperBounds = wildcardType.getUpperBounds();
|
||||
if (upperBounds.length == 1) {
|
||||
argType = upperBounds[0];
|
||||
}
|
||||
}
|
||||
this.itemType = argType;
|
||||
array = false;
|
||||
} else if (fieldClass.isArray()) {
|
||||
this.itemType = fieldClass.getComponentType();
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.alibaba.json.bvt.bug;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/01/2017.
|
||||
*/
|
||||
public class Issue998 extends TestCase {
|
||||
public void test_for_issue() throws Exception {
|
||||
Model model = JSON.parseObject("{\"items\":[{\"id\":123}]}", Model.class);
|
||||
assertNotNull(model);
|
||||
assertNotNull(model.items);
|
||||
assertEquals(1, model.items.size());
|
||||
assertEquals(123, model.items.get(0).id);
|
||||
}
|
||||
|
||||
public static class Model {
|
||||
public List<? extends Item> items;
|
||||
}
|
||||
|
||||
public static class Item {
|
||||
public int id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user