use of com.alibaba.fastjson.serializer.SimplePropertyPreFilter in project fastjson by alibaba.
the class SimplePropertyPreFilterTest method test_map_name.
public void test_map_name() throws Exception {
SimplePropertyPreFilter filter = new SimplePropertyPreFilter("name");
Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(map, filter));
}
use of com.alibaba.fastjson.serializer.SimplePropertyPreFilter in project fastjson by alibaba.
the class SimplePropertyPreFilterTest method test_name_0.
public void test_name_0() throws Exception {
SimplePropertyPreFilter filter = new SimplePropertyPreFilter("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_map_id.
public void test_map_id() throws Exception {
SimplePropertyPreFilter filter = new SimplePropertyPreFilter("id");
Assert.assertEquals("{\"id\":123}", JSON.toJSONString(map, filter));
}
use of com.alibaba.fastjson.serializer.SimplePropertyPreFilter in project fastjson by alibaba.
the class PropertyPreFilterClassLevelTest 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);
}
use of com.alibaba.fastjson.serializer.SimplePropertyPreFilter in project ready-x by CodePlayer.
the class JSONUtil method encodeWithExclude.
/**
* 将Java对象编码为JSON字符串
*
* @param obj 指定的任意对象
* @param excludeProperties 需要排除的属性数组
* @return
*/
public static final String encodeWithExclude(Object obj, String... excludeProperties) {
SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
Collections.addAll(filter.getExcludes(), excludeProperties);
return JSON.toJSONString(obj, filter, SerializerFeature.DisableCircularReferenceDetect);
}
Aggregations