Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
422 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
src/test/java/com/alibaba/json/bvt/serializer/filters/ValueFilterTest_field.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package com.alibaba.json.bvt.serializer.filters; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.serializer.JSONSerializer; | ||
import com.alibaba.fastjson.serializer.SerializeWriter; | ||
import com.alibaba.fastjson.serializer.ValueFilter; | ||
import com.alibaba.json.bvt.serializer.PropertyFilterTest; | ||
import com.alibaba.json.bvt.serializer.PropertyFilterTest.A; | ||
|
||
public class ValueFilterTest_field extends TestCase { | ||
|
||
public void test_valuefilter() throws Exception { | ||
ValueFilter filter = new ValueFilter() { | ||
|
||
public Object process(Object source, String name, Object value) { | ||
if (name.equals("id")) { | ||
return "AAA"; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
}; | ||
|
||
SerializeWriter out = new SerializeWriter(); | ||
JSONSerializer serializer = new JSONSerializer(out); | ||
serializer.getValueFilters().add(filter); | ||
|
||
A a = new A(); | ||
serializer.write(a); | ||
|
||
String text = out.toString(); | ||
Assert.assertEquals("{\"id\":\"AAA\"}", text); | ||
} | ||
|
||
public void test_toJSONString() throws Exception { | ||
ValueFilter filter = new ValueFilter() { | ||
|
||
public Object process(Object source, String name, Object value) { | ||
if (name.equals("id")) { | ||
return "AAA"; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
}; | ||
|
||
Assert.assertEquals("{\"id\":\"AAA\"}", JSON.toJSONString(new A(), filter)); | ||
} | ||
|
||
public void test_valuefilter_1() throws Exception { | ||
ValueFilter filter = new ValueFilter() { | ||
|
||
public Object process(Object source, String name, Object value) { | ||
if (name.equals("name")) { | ||
return "AAA"; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
}; | ||
|
||
SerializeWriter out = new SerializeWriter(); | ||
JSONSerializer serializer = new JSONSerializer(out); | ||
serializer.getValueFilters().add(filter); | ||
|
||
A a = new A(); | ||
serializer.write(a); | ||
|
||
String text = out.toString(); | ||
Assert.assertEquals("{\"id\":0,\"name\":\"AAA\"}", text); | ||
} | ||
|
||
public void test_valuefilter_2() throws Exception { | ||
ValueFilter filter = new ValueFilter() { | ||
|
||
public Object process(Object source, String name, Object value) { | ||
if (name.equals("name")) { | ||
return "AAA"; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
}; | ||
|
||
SerializeWriter out = new SerializeWriter(); | ||
JSONSerializer serializer = new JSONSerializer(out); | ||
serializer.getValueFilters().add(filter); | ||
|
||
Map<String, Object> map = new HashMap<String, Object>(); | ||
map.put("name", null); | ||
serializer.write(map); | ||
|
||
String text = out.toString(); | ||
Assert.assertEquals("{\"name\":\"AAA\"}", text); | ||
} | ||
|
||
public void test_valuefilter_3() throws Exception { | ||
ValueFilter filter = new ValueFilter() { | ||
|
||
public Object process(Object source, String name, Object value) { | ||
if (name.equals("name")) { | ||
return null; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
}; | ||
|
||
SerializeWriter out = new SerializeWriter(); | ||
JSONSerializer serializer = new JSONSerializer(out); | ||
serializer.getValueFilters().add(filter); | ||
|
||
Map<String, Object> map = new HashMap<String, Object>(); | ||
map.put("name", "AA"); | ||
serializer.write(map); | ||
|
||
String text = out.toString(); | ||
Assert.assertEquals("{}", text); | ||
} | ||
|
||
public static class Bean { | ||
|
||
public int id; | ||
public String name; | ||
|
||
|
||
} | ||
} |
140 changes: 140 additions & 0 deletions
140
src/test/java/com/alibaba/json/bvt/serializer/filters/ValueFilterTest_field_boolean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package com.alibaba.json.bvt.serializer.filters; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.serializer.JSONSerializer; | ||
import com.alibaba.fastjson.serializer.SerializeWriter; | ||
import com.alibaba.fastjson.serializer.ValueFilter; | ||
import com.alibaba.json.bvt.serializer.PropertyFilterTest; | ||
import com.alibaba.json.bvt.serializer.PropertyFilterTest.A; | ||
|
||
public class ValueFilterTest_field_boolean extends TestCase { | ||
|
||
public void test_valuefilter() throws Exception { | ||
ValueFilter filter = new ValueFilter() { | ||
|
||
public Object process(Object source, String name, Object value) { | ||
if (name.equals("id")) { | ||
return "AAA"; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
}; | ||
|
||
SerializeWriter out = new SerializeWriter(); | ||
JSONSerializer serializer = new JSONSerializer(out); | ||
serializer.getValueFilters().add(filter); | ||
|
||
A a = new A(); | ||
serializer.write(a); | ||
|
||
String text = out.toString(); | ||
Assert.assertEquals("{\"id\":\"AAA\"}", text); | ||
} | ||
|
||
public void test_toJSONString() throws Exception { | ||
ValueFilter filter = new ValueFilter() { | ||
|
||
public Object process(Object source, String name, Object value) { | ||
if (name.equals("id")) { | ||
return "AAA"; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
}; | ||
|
||
Assert.assertEquals("{\"id\":\"AAA\"}", JSON.toJSONString(new A(), filter)); | ||
} | ||
|
||
public void test_valuefilter_1() throws Exception { | ||
ValueFilter filter = new ValueFilter() { | ||
|
||
public Object process(Object source, String name, Object value) { | ||
if (name.equals("name")) { | ||
return "AAA"; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
}; | ||
|
||
SerializeWriter out = new SerializeWriter(); | ||
JSONSerializer serializer = new JSONSerializer(out); | ||
serializer.getValueFilters().add(filter); | ||
|
||
A a = new A(); | ||
serializer.write(a); | ||
|
||
String text = out.toString(); | ||
Assert.assertEquals("{\"id\":0,\"name\":\"AAA\"}", text); | ||
} | ||
|
||
public void test_valuefilter_2() throws Exception { | ||
ValueFilter filter = new ValueFilter() { | ||
|
||
public Object process(Object source, String name, Object value) { | ||
if (name.equals("name")) { | ||
return "AAA"; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
}; | ||
|
||
SerializeWriter out = new SerializeWriter(); | ||
JSONSerializer serializer = new JSONSerializer(out); | ||
serializer.getValueFilters().add(filter); | ||
|
||
Map<String, Object> map = new HashMap<String, Object>(); | ||
map.put("name", null); | ||
serializer.write(map); | ||
|
||
String text = out.toString(); | ||
Assert.assertEquals("{\"name\":\"AAA\"}", text); | ||
} | ||
|
||
public void test_valuefilter_3() throws Exception { | ||
ValueFilter filter = new ValueFilter() { | ||
|
||
public Object process(Object source, String name, Object value) { | ||
if (name.equals("name")) { | ||
return null; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
}; | ||
|
||
SerializeWriter out = new SerializeWriter(); | ||
JSONSerializer serializer = new JSONSerializer(out); | ||
serializer.getValueFilters().add(filter); | ||
|
||
Map<String, Object> map = new HashMap<String, Object>(); | ||
map.put("name", "AA"); | ||
serializer.write(map); | ||
|
||
String text = out.toString(); | ||
Assert.assertEquals("{}", text); | ||
} | ||
|
||
public static class Bean { | ||
|
||
public boolean id; | ||
public String name; | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.