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

Commit

Permalink
bug fixed gereric base class, for issue 604. #604
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed May 4, 2016
1 parent 4488fbb commit ea4bbbc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
Expand Down Expand Up @@ -1160,8 +1161,12 @@ private void _get(MethodVisitor mw, Context context, FieldInfo fieldInfo) {
}
} else {
mw.visitVarInsn(ALOAD, context.var("entity"));
mw.visitFieldInsn(GETFIELD, type(fieldInfo.declaringClass), fieldInfo.field.getName(),
desc(fieldInfo.fieldClass));
Field field = fieldInfo.field;
mw.visitFieldInsn(GETFIELD, type(fieldInfo.declaringClass), field.getName(),
desc(field.getType()));
if (!field.getType().equals(fieldInfo.fieldClass)) {
mw.visitTypeInsn(CHECKCAST, type(fieldInfo.fieldClass)); // cast
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public static class MyResultResult extends BaseResult<String> {
}

public static class BaseResult<T> implements Serializable {
private T data;
public T getData() {
return data;
}
public T data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.alibaba.json.bvt.serializer;

import java.io.Serializable;

import com.alibaba.fastjson.JSON;

import junit.framework.TestCase;

public class GenericTypeTest2 extends TestCase {

public void test_gerneric() throws Exception {
MyResultResult result = new MyResultResult();
JSON.toJSONString(result);
}

public static class MyResultResult extends BaseResult<String> {
}

public static class BaseResult<T> implements Serializable {
private T data;
public T getData() {
return data;
}
}
}

0 comments on commit ea4bbbc

Please sign in to comment.