bug fixed for issue #1265

This commit is contained in:
wenshao
2017-07-23 00:18:57 +08:00
parent c0b096333a
commit ec98cc03a3
2 changed files with 20 additions and 10 deletions
@@ -31,16 +31,22 @@ public class DefaultFieldDeserializer extends FieldDeserializer {
@Override
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
if (fieldValueDeserilizer == null) {
fieldValueDeserilizer = parser.config.getDeserializer(fieldInfo.fieldClass, fieldInfo.fieldType);
}
if (objectType instanceof ParameterizedType) {
ParseContext objContext = parser.contex;
objContext.type = objectType;
if (this.fieldValueDeserilizer == null) {
this.fieldValueDeserilizer = parser.config.getDeserializer(fieldInfo.fieldClass, fieldInfo.fieldType);
}
Type fieldType = fieldInfo.fieldType;
if (objectType instanceof ParameterizedType) {
ParseContext objContext = parser.contex;
if (objContext != null) {
objContext.type = objectType;
}
fieldType = FieldInfo.getFieldType(this.clazz, objectType, fieldType);
fieldValueDeserilizer = parser.config.getDeserializer(fieldType);
}
if (fieldType instanceof ParameterizedType
&& objectType instanceof ParameterizedType) {
ParameterizedType fieldParamType = (ParameterizedType) fieldType;
@@ -8,16 +8,20 @@ import junit.framework.TestCase;
/**
* Created by wenshao on 22/07/2017.
*/
public class Isse1265 extends TestCase {
public class Issue1265 extends TestCase {
public void test_0() throws Exception {
Object t = JSON.parseObject("{\"value\":{\"id\":123}}", new TypeReference<Response>(){}).value;
assertEquals(123, ((JSONObject) t).getIntValue("id"));
T1 t1 = JSON.parseObject("{\"value\":{\"id\":123}}", new TypeReference<Response<T1>>(){}).value;
assertEquals(123, t1.id);
T1 t1_x = JSON.parseObject("{\"value\":{\"id\":123}}", new TypeReference<Response<T1>>(){}).value;
assertEquals(123, t1_x.id);
T2 t2 = JSON.parseObject("{\"value\":{\"id\":123}}", new TypeReference<Response<T2>>(){}).value;
assertEquals(123, t2.id);
Object t = JSON.parseObject("{\"value\":{\"id\":123}}", new TypeReference<Response>(){}).value;
assertEquals(123, ((JSONObject) t).getIntValue("id"));
}
public static class Response<T> {