use of com.alibaba.fastjson.serializer.SimplePropertyPreFilter in project fastjson by alibaba.
the class SimplePropertyPreFilterTest method test_all_map.
public void test_all_map() throws Exception {
SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VO.class);
String text = JSON.toJSONString(map, filter);
Assert.assertTrue("{\"id\":123,\"name\":\"sandzhangtoo\"}".equals(text) || "{\"name\":\"sandzhangtoo\",\"id\":123}".equals(text));
}
use of com.alibaba.fastjson.serializer.SimplePropertyPreFilter in project fastjson by alibaba.
the class SimplePropertyPreFilterTest method test_exclude_name.
public void test_exclude_name() throws Exception {
SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VO.class);
filter.getExcludes().add("name");
Assert.assertEquals("{\"id\":123}", JSON.toJSONString(vo, filter));
}
use of com.alibaba.fastjson.serializer.SimplePropertyPreFilter in project fastjson by alibaba.
the class SimplePropertyPreFilterTest method test_name.
public void test_name() throws Exception {
SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VO.class, "name");
Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(vo, filter));
}
use of com.alibaba.fastjson.serializer.SimplePropertyPreFilter in project fastjson by alibaba.
the class SimplePropertyPreFilterTest method test_exclude_id.
public void test_exclude_id() throws Exception {
SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VO.class);
filter.getExcludes().add("id");
Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(vo, filter));
}
use of com.alibaba.fastjson.serializer.SimplePropertyPreFilter in project fastjson by alibaba.
the class PropertyPreFilterClassLevelTest_private method test_0.
public void test_0() throws Exception {
Object[] array = { new ModelA(), new ModelB() };
SerializeConfig config = new SerializeConfig();
//
config.addFilter(//
ModelA.class, new SimplePropertyPreFilter("name"));
//
config.addFilter(//
ModelB.class, new SimplePropertyPreFilter("id"));
String text2 = JSON.toJSONString(array, config);
Assert.assertEquals("[{},{\"id\":1002}]", text2);
String text = JSON.toJSONString(array);
Assert.assertEquals("[{\"id\":1001},{\"id\":1002}]", text);
}
Aggregations