mirror of
https://github.com/alibaba/fastjson.git
synced 2026-10-25 02:57:41 +08:00
support BeforeFilter
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.json.bvt.serializer;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.BeforeFilter;
|
||||
|
||||
public class BeforeFilterTest extends TestCase {
|
||||
public void test_beforeFilter() throws Exception {
|
||||
BeforeFilter filter = new BeforeFilter() {
|
||||
|
||||
@Override
|
||||
public void writeBefore(Object object) {
|
||||
this.writeKeyValue("id", 123);
|
||||
}
|
||||
};
|
||||
Assert.assertEquals("{\"id\":123}",JSON.toJSONString( new VO(), filter));
|
||||
}
|
||||
|
||||
public void test_beforeFilter2() throws Exception {
|
||||
BeforeFilter filter = new BeforeFilter() {
|
||||
|
||||
@Override
|
||||
public void writeBefore(Object object) {
|
||||
this.writeKeyValue("id", 123);
|
||||
this.writeKeyValue("name", "wenshao");
|
||||
}
|
||||
};
|
||||
Assert.assertEquals("{\"id\":123,\"name\":\"wenshao\"}", JSON.toJSONString(new VO(), filter));
|
||||
}
|
||||
|
||||
private static class VO {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.json.bvt.serializer;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.BeforeFilter;
|
||||
|
||||
public class BeforeFilterTest2 extends TestCase {
|
||||
public void test_beforeFilter() throws Exception {
|
||||
BeforeFilter filter = new BeforeFilter() {
|
||||
|
||||
@Override
|
||||
public void writeBefore(Object object) {
|
||||
this.writeKeyValue("id", 123);
|
||||
}
|
||||
};
|
||||
Assert.assertEquals(JSON.toJSONString(new VO(), filter), "{\"id\":123}");
|
||||
}
|
||||
|
||||
public void test_beforeFilter2() throws Exception {
|
||||
BeforeFilter filter = new BeforeFilter() {
|
||||
|
||||
@Override
|
||||
public void writeBefore(Object object) {
|
||||
this.writeKeyValue("id", 123);
|
||||
this.writeKeyValue("name", "wenshao");
|
||||
}
|
||||
};
|
||||
Assert.assertEquals(JSON.toJSONString(new VO(), filter), "{\"id\":123,\"name\":\"wenshao\"}");
|
||||
}
|
||||
|
||||
public static class VO {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user