use of com.alibaba.fastjson.serializer.PropertyFilter in project fastjson by alibaba.
the class PropertyFilter_short method test_4.
public void test_4() throws Exception {
PropertyFilter filter = new PropertyFilter() {
public boolean apply(Object source, String name, Object value) {
if ("name".equals(name)) {
return false;
}
return true;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getPropertyFilters().add(filter);
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", 3);
map.put("name", "chennp2008");
serializer.write(map);
String text = out.toString();
Assert.assertEquals("{\"id\":3}", text);
}
use of com.alibaba.fastjson.serializer.PropertyFilter in project fastjson by alibaba.
the class PropertyFilter_short method test_0.
public void test_0() throws Exception {
PropertyFilter filter = new PropertyFilter() {
public boolean apply(Object source, String name, Object value) {
return false;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getPropertyFilters().add(filter);
A a = new A();
serializer.write(a);
String text = out.toString();
Assert.assertEquals("{}", text);
}
use of com.alibaba.fastjson.serializer.PropertyFilter in project fastjson by alibaba.
the class PropertyFilter_short method test_2.
public void test_2() throws Exception {
PropertyFilter filter = new PropertyFilter() {
public boolean apply(Object source, String name, Object value) {
if ("name".equals(name)) {
return true;
}
return false;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getPropertyFilters().add(filter);
A a = new A();
a.setName("chennp2008");
serializer.write(a);
String text = out.toString();
Assert.assertEquals("{\"name\":\"chennp2008\"}", text);
}
use of com.alibaba.fastjson.serializer.PropertyFilter in project otter by alibaba.
the class JsonUtils method marshalToString.
/**
* 可以允许指定一些过滤字段进行生成json对象
*/
public static String marshalToString(Object obj, String... fliterFields) {
final List<String> propertyFliters = Arrays.asList(fliterFields);
SerializeWriter out = new SerializeWriter();
try {
JSONSerializer serializer = new JSONSerializer(out);
serializer.getPropertyFilters().add(new PropertyFilter() {
public boolean apply(Object source, String name, Object value) {
return !propertyFliters.contains(name);
}
});
serializer.write(obj);
return out.toString();
} finally {
out.close();
}
}
use of com.alibaba.fastjson.serializer.PropertyFilter in project canal by alibaba.
the class JsonUtils method marshalToString.
/**
* 可以允许指定一些过滤字段进行生成json对象
*/
public static String marshalToString(Object obj, String... fliterFields) {
final List<String> propertyFliters = Arrays.asList(fliterFields);
SerializeWriter out = new SerializeWriter();
try {
JSONSerializer serializer = new JSONSerializer(out);
serializer.getPropertyFilters().add(new PropertyFilter() {
public boolean apply(Object source, String name, Object value) {
return !propertyFliters.contains(name);
}
});
serializer.write(obj);
return out.toString();
} finally {
out.close();
}
}
Aggregations