mirror of
https://github.com/alibaba/fastjson.git
synced 2026-10-28 22:04:04 +08:00
bug fixed & add testcase
This commit is contained in:
@@ -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'}}");
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user