diff --git a/src/main/java/com/alibaba/fastjson/parser/DefaultJSONParser.java b/src/main/java/com/alibaba/fastjson/parser/DefaultJSONParser.java index d17b87ad5..2df0d5b22 100755 --- a/src/main/java/com/alibaba/fastjson/parser/DefaultJSONParser.java +++ b/src/main/java/com/alibaba/fastjson/parser/DefaultJSONParser.java @@ -446,6 +446,10 @@ public class DefaultJSONParser extends AbstractJSONParser implements Closeable { } else { lexer.nextToken(); value = parse(); + + if (object.getClass() == JSONObject.class) { + key = key.toString(); + } object.put(key, value); if (lexer.token() == JSONToken.RBRACE) { diff --git a/src/test/java/com/alibaba/json/bvt/bug/Bug_for_zengjie.java b/src/test/java/com/alibaba/json/bvt/bug/Bug_for_zengjie.java new file mode 100644 index 000000000..ec6514450 --- /dev/null +++ b/src/test/java/com/alibaba/json/bvt/bug/Bug_for_zengjie.java @@ -0,0 +1,12 @@ +package com.alibaba.json.bvt.bug; + +import junit.framework.TestCase; + +import com.alibaba.fastjson.JSON; + + +public class Bug_for_zengjie extends TestCase { + public void test_0 () throws Exception { + JSON.parse("{123:'abc','value':{123:'abc'}}"); + } +} diff --git a/src/test/java/com/alibaba/json/bvt/serializer/PrePropertyFilterTest.java b/src/test/java/com/alibaba/json/bvt/serializer/PrePropertyFilterTest.java new file mode 100644 index 000000000..0e919414c --- /dev/null +++ b/src/test/java/com/alibaba/json/bvt/serializer/PrePropertyFilterTest.java @@ -0,0 +1,30 @@ +package com.alibaba.json.bvt.serializer; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.serializer.JSONSerializer; +import com.alibaba.fastjson.serializer.PropertyPreFilter; + +public class PrePropertyFilterTest extends TestCase { + + public void test_0() throws Exception { + class VO { + public int getId() { throw new RuntimeException(); } + } + + PropertyPreFilter filter = new PropertyPreFilter () { + public boolean apply(JSONSerializer serializer, Object source, String name) { + return false; + } + }; + + VO vo = new VO(); + + String text = JSON.toJSONString(vo, filter); + Assert.assertEquals("{}", text); + } + +} diff --git a/src/test/java/com/alibaba/json/bvt/serializer/PropertyFilterTest2.java b/src/test/java/com/alibaba/json/bvt/serializer/PropertyFilterTest2.java new file mode 100644 index 000000000..651f3c214 --- /dev/null +++ b/src/test/java/com/alibaba/json/bvt/serializer/PropertyFilterTest2.java @@ -0,0 +1,33 @@ +package com.alibaba.json.bvt.serializer; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.serializer.PropertyFilter; + +public class PropertyFilterTest2 extends TestCase { + + public void test_0() throws Exception { + class VO { + public int id; + public String name; + } + + PropertyFilter filter = new PropertyFilter() { + + public boolean apply(Object source, String name, Object value) { + return "id".equals(name); + } + }; + + VO vo = new VO(); + vo.id = 123; + vo.name = "gaotie"; + + String text = JSON.toJSONString(vo, filter); + Assert.assertEquals("{\"id\":123}", text); + } + +}