Search in sources :

Example 16 with SimplePropertyPreFilter

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));
}
Also used : SimplePropertyPreFilter(com.alibaba.fastjson.serializer.SimplePropertyPreFilter)

Example 17 with SimplePropertyPreFilter

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));
}
Also used : SimplePropertyPreFilter(com.alibaba.fastjson.serializer.SimplePropertyPreFilter)

Example 18 with SimplePropertyPreFilter

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));
}
Also used : SimplePropertyPreFilter(com.alibaba.fastjson.serializer.SimplePropertyPreFilter)

Example 19 with SimplePropertyPreFilter

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));
}
Also used : SimplePropertyPreFilter(com.alibaba.fastjson.serializer.SimplePropertyPreFilter)

Example 20 with SimplePropertyPreFilter

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);
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) SimplePropertyPreFilter(com.alibaba.fastjson.serializer.SimplePropertyPreFilter)

Aggregations

SimplePropertyPreFilter (com.alibaba.fastjson.serializer.SimplePropertyPreFilter)20 SerializeConfig (com.alibaba.fastjson.serializer.SerializeConfig)3 Date (java.util.Date)1 HashMap (java.util.HashMap)1