diff --git a/src/main/java/com/alibaba/fastjson/util/FieldInfo.java b/src/main/java/com/alibaba/fastjson/util/FieldInfo.java index 65c0e0463..993eaac2c 100644 --- a/src/main/java/com/alibaba/fastjson/util/FieldInfo.java +++ b/src/main/java/com/alibaba/fastjson/util/FieldInfo.java @@ -14,6 +14,7 @@ import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; import java.util.Map; +import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.annotation.JSONField; public class FieldInfo implements Comparable { @@ -352,8 +353,9 @@ public class FieldInfo implements Comparable { } if (changed) { - fieldType = new ParameterizedTypeImpl(arguments, parameterizedFieldType.getOwnerType(), - parameterizedFieldType.getRawType()); + ParameterizedTypeImpl fieldTypeRaw = new ParameterizedTypeImpl(arguments, parameterizedFieldType.getOwnerType(), + parameterizedFieldType.getRawType()); + fieldType = TypeReference.intern(fieldTypeRaw); return fieldType; } } diff --git a/src/test/java/com/alibaba/json/bvt/typeRef/TypeReferenceTest14.java b/src/test/java/com/alibaba/json/bvt/typeRef/TypeReferenceTest14.java new file mode 100644 index 000000000..33cd034e6 --- /dev/null +++ b/src/test/java/com/alibaba/json/bvt/typeRef/TypeReferenceTest14.java @@ -0,0 +1,61 @@ +package com.alibaba.json.bvt.typeRef; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.alibaba.fastjson.annotation.JSONField; +import com.alibaba.fastjson.parser.ParserConfig; +import java.util.List; +import junit.framework.TestCase; + +import java.io.Serializable; + +/** + * Created by wenshao on 09/02/2017. + */ +public class TypeReferenceTest14 extends TestCase { + public void test_0() throws Exception { + String str = "{\"result\":{\"item\":[{\"key\":\"123\"}]}}"; + + ParserConfig config = new ParserConfig(); + JSONObject.parseObject(str, OpenSearchResponse.class, config); + JSONObject.parseObject(str + , new TypeReference>() {}.getType() + , config, JSON.DEFAULT_PARSER_FEATURE); + + int size = config.getDeserializers().size(); + for (int i = 0; i < 100 * 1; ++i) { + JSONObject.parseObject(str + , new TypeReference>() {}.getType() + , config, JSON.DEFAULT_PARSER_FEATURE); + assertEquals(size, config.getDeserializers().size()); + } + } + + public static class OpenSearchResponse { + + private OpenSearchResult result; + + public OpenSearchResult getResult() { + return result; + } + + public void setResult(OpenSearchResult result) { + this.result = result; + } + + + } + + public static class OpenSearchResult { + private List item; + + public List getItem() { + return item; + } + + public void setItem(List item) { + this.item = item; + } + } +}