bug fixed for IgnoreNonFieldGetter

This commit is contained in:
高铁
2015-08-23 01:20:42 +08:00
parent 59c036765d
commit 8d14aecfde
4 changed files with 54 additions and 9 deletions
@@ -1142,15 +1142,6 @@ public class ASMSerializerFactory implements Opcodes {
// if true
mw.visitJumpInsn(IFNE, _end);
}
} else {
mw.visitVarInsn(ALOAD, context.var("out"));
mw.visitFieldInsn(GETSTATIC, "com/alibaba/fastjson/serializer/SerializerFeature", "IgnoreNonFieldGetter",
"Lcom/alibaba/fastjson/serializer/SerializerFeature;");
mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "isEnabled",
"(Lcom/alibaba/fastjson/serializer/SerializerFeature;)Z");
// if true
mw.visitJumpInsn(IFNE, _end);
}
_notWriteDefault(mw, property, context, _end);
@@ -1181,6 +1172,17 @@ public class ASMSerializerFactory implements Opcodes {
mw.visitJumpInsn(IFEQ, _end);
_labelApply(mw, property, context, _end);
if (property.getField() == null) {
mw.visitVarInsn(ALOAD, context.var("out"));
mw.visitFieldInsn(GETSTATIC, "com/alibaba/fastjson/serializer/SerializerFeature", "IgnoreNonFieldGetter",
"Lcom/alibaba/fastjson/serializer/SerializerFeature;");
mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "isEnabled",
"(Lcom/alibaba/fastjson/serializer/SerializerFeature;)Z");
// if true
mw.visitJumpInsn(IFNE, _end);
}
}
private void _labelApply(MethodVisitor mw, FieldInfo property, Context context, Label _end) {
@@ -0,0 +1,22 @@
package com.alibaba.json.bvt.serializer;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.json.bvtVO.PayDO;
import junit.framework.TestCase;
public class IgnoreGetMethodTest extends TestCase {
// public void test_nested_object() {
// QueryResult result = new QueryResult();
// result.setPay(new PayDO());
// String json = JSON.toJSONString(result, SerializerFeature.IgnoreNonFieldGetter);
// System.out.println(json);
// }
public void test() {
PayDO result = new PayDO();
String json = JSON.toJSONString(result, SerializerFeature.IgnoreNonFieldGetter);
System.out.println(json);
}
}
@@ -0,0 +1,8 @@
package com.alibaba.json.bvtVO;
public class PayDO {
public Integer getCurrentSubPayOrder() {
throw new RuntimeException("non getter getXXX method should not be called");
}
}
@@ -0,0 +1,13 @@
package com.alibaba.json.bvtVO;
public class QueryResult {
private PayDO pay;
public void setPay(PayDO pay) {
this.pay = pay;
}
public PayDO getPay() {
return pay;
}
}