Skip to content

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 2201258 commit 2b90431
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 20 deletions.
Expand Up @@ -392,21 +392,6 @@ public ObjectSerializer createJavaBeanSerializer(SerializeBeanInfo beanInfo) thr


byte[] code = cw.toByteArray(); byte[] code = cw.toByteArray();


// if(JSON.DUMP_CLASS != null){
// FileOutputStream fos=null;
// try {
// fos=new FileOutputStream(JSON.DUMP_CLASS+ File.separator
// + classNameType + ".class");
// fos.write(code);
// }catch (Exception ex){
// System.err.println("FASTJSON dump class:"+classNameType+"失败:"+ex.getMessage());
// }finally {
// if(fos!=null){
// fos.close();
// }
// }
// }

Class<?> exampleClass = classLoader.defineClassPublic(classNameFull, code, 0, code.length); Class<?> exampleClass = classLoader.defineClassPublic(classNameFull, code, 0, code.length);
Constructor<?> constructor = exampleClass.getConstructor(SerializeBeanInfo.class); Constructor<?> constructor = exampleClass.getConstructor(SerializeBeanInfo.class);
Object instance = constructor.newInstance(beanInfo); Object instance = constructor.newInstance(beanInfo);
Expand Down Expand Up @@ -1164,15 +1149,19 @@ private void _double(Class<?> clazz, MethodVisitor mw, FieldInfo property, Conte
mw.visitLabel(end_); mw.visitLabel(end_);
} }


private void _get(MethodVisitor mw, Context context, FieldInfo property) { private void _get(MethodVisitor mw, Context context, FieldInfo fieldInfo) {
Method method = property.method; Method method = fieldInfo.method;
if (method != null) { if (method != null) {
mw.visitVarInsn(ALOAD, context.var("entity")); mw.visitVarInsn(ALOAD, context.var("entity"));
mw.visitMethodInsn(INVOKEVIRTUAL, type(method.getDeclaringClass()), method.getName(), desc(method)); Class<?> declaringClass = method.getDeclaringClass();
mw.visitMethodInsn(INVOKEVIRTUAL, type(declaringClass), method.getName(), desc(method));
if (!declaringClass.equals(fieldInfo.fieldClass)) {
mw.visitTypeInsn(CHECKCAST, type(fieldInfo.fieldClass)); // cast
}
} else { } else {
mw.visitVarInsn(ALOAD, context.var("entity")); mw.visitVarInsn(ALOAD, context.var("entity"));
mw.visitFieldInsn(GETFIELD, type(property.declaringClass), property.field.getName(), mw.visitFieldInsn(GETFIELD, type(fieldInfo.declaringClass), fieldInfo.field.getName(),
desc(property.fieldClass)); desc(fieldInfo.fieldClass));
} }
} }


Expand Down
25 changes: 25 additions & 0 deletions src/test/java/com/alibaba/json/bvt/serializer/GenericTypeTest.java
@@ -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 GenericTypeTest 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;
}
}
}
19 changes: 19 additions & 0 deletions src/test/java/com/alibaba/json/bvtVO/bbc/BaseResult.java
@@ -0,0 +1,19 @@
package com.alibaba.json.bvtVO.bbc;


import java.io.Serializable;

public class BaseResult<T> implements Serializable {
private T data;
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}


public BaseResult() {

}
}
9 changes: 9 additions & 0 deletions src/test/java/com/alibaba/json/bvtVO/bbc/MyResultResult.java
@@ -0,0 +1,9 @@
package com.alibaba.json.bvtVO.bbc;


public class MyResultResult extends BaseResult<String> {

public MyResultResult(){

}
}

0 comments on commit 2b90431

Please sign in to comment.