use of com.alibaba.fastjson.serializer.NameFilter in project fastjson by alibaba.
the class NameFilterTest_boolean_field method test_namefilter.
public void test_namefilter() throws Exception {
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (value != null) {
Assert.assertTrue(value instanceof Boolean);
}
if (name.equals("id")) {
return "ID";
}
return name;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getNameFilters().add(filter);
Bean a = new Bean();
serializer.write(a);
String text = out.toString();
Assert.assertEquals("{\"ID\":false}", text);
}
use of com.alibaba.fastjson.serializer.NameFilter in project fastjson by alibaba.
the class NameFilterTest_byte method test_namefilter.
public void test_namefilter() throws Exception {
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (value != null) {
Assert.assertTrue(value instanceof Byte);
}
if (name.equals("id")) {
return "ID";
}
return name;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getNameFilters().add(filter);
Bean a = new Bean();
serializer.write(a);
String text = out.toString();
Assert.assertEquals("{\"ID\":0}", text);
}
use of com.alibaba.fastjson.serializer.NameFilter in project fastjson by alibaba.
the class NameFilterTest_byte method test_namefilter_1.
public void test_namefilter_1() throws Exception {
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (name.equals("id")) {
return "ID";
}
return name;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getNameFilters().add(filter);
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", (byte) 0);
serializer.write(map);
String text = out.toString();
Assert.assertEquals("{\"ID\":0}", text);
}
use of com.alibaba.fastjson.serializer.NameFilter in project fastjson by alibaba.
the class NameFilterTest_double method test_namefilter_1.
public void test_namefilter_1() throws Exception {
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (name.equals("id")) {
return "ID";
}
return name;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getNameFilters().add(filter);
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", 0);
serializer.write(map);
String text = out.toString();
Assert.assertEquals("{\"ID\":0}", text);
}
use of com.alibaba.fastjson.serializer.NameFilter in project fastjson by alibaba.
the class NameFilterTest_double_field method test_namefilter_1.
public void test_namefilter_1() throws Exception {
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (name.equals("id")) {
return "ID";
}
return name;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getNameFilters().add(filter);
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", 0);
serializer.write(map);
String text = out.toString();
Assert.assertEquals("{\"ID\":0}", text);
}
Aggregations