Java 类com.alibaba.fastjson.serializer.SimplePropertyPreFilter 实例源码

项目:GitHub    文件:PropertyPreFilterClassLevelTest.java   
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);


}
项目:GitHub    文件:PropertyPreFilterClassLevelTest_private.java   
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);


}
项目:GitHub    文件:SimplePropertyPreFilterTest.java   
public void test_name_a() throws Exception {
    SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VO.class, "name");
    Assert.assertEquals(VO.class, filter.getClazz());
    Assert.assertEquals(1, filter.getIncludes().size());
    Assert.assertTrue(filter.apply(null, null, null));

    String text = JSON.toJSONString(a, filter);
    Assert.assertTrue("{\"id\":123,\"name\":\"sandzhangtoo\"}".equals(text) || "{\"name\":\"sandzhangtoo\",\"id\":123}".equals(text));
}
项目:GitHub    文件:Issue763.java   
public void test_0() throws Exception {
    Map<String, Object> reqDto = new HashMap<String, Object>();
    reqDto.put("name", "aaaa");
    reqDto.put("age", 50);
    reqDto.put("address", "深圳南山");

    SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
    filter.getExcludes().add("name");

    // SerializeConfig.getGlobalInstance().addFilter(Map.class, filter);
    SerializeConfig config = new SerializeConfig();
    config.addFilter(HashMap.class, filter);
    System.out.println(JSON.toJSONString(reqDto, config));
}
项目:GitHub    文件:Issue184.java   
public void test_for_issue() throws Exception {
    SimplePropertyPreFilter filter = new SimplePropertyPreFilter();

    VO vo = new VO();
    vo.setDate(new Date());
    String text = JSON.toJSONString(vo, filter);
    System.out.println(text);
}
项目:GitHub    文件:Bug_for_issue_285.java   
public void test_for_issue() throws Exception {
    VO vo = new VO();
    vo.v1 = new V1();
    vo.v1.v2 = new V2();
    vo.v1.v2.v3 = new V3();
    vo.v1.v2.v3.v4 = new V4();

    SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
    filter.setMaxLevel(2);
    String text = JSON.toJSONString(vo, filter);
    Assert.assertEquals("{\"v1\":{\"v2\":{}}}", text);
}
项目:android-Stupid-Adapter    文件:JsonUtils.java   
/**
 * 将给定的目标对象根据指定的过滤参数转换成 JSON 格式的字符串。
 * 
 * @param target
 * @param clazz
 * @param properties
 * @return
 */
public static String toJSONString(Object target, Class<?> clazz,
        String... properties) {
    if (target == null)
        return EMPTY_JSON;
    SimplePropertyPreFilter filter = new SimplePropertyPreFilter(clazz,
            properties);
    return JSON.toJSONString(target, filter);
}
项目:GitHub    文件:SimplePropertyPreFilterTest.java   
public void test_name() throws Exception {
    SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VO.class, "name");
    Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(vo, filter));
}
项目:GitHub    文件:SimplePropertyPreFilterTest.java   
public void test_name_0() throws Exception {
    SimplePropertyPreFilter filter = new SimplePropertyPreFilter("name");
    Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(vo, filter));
}
项目:GitHub    文件:SimplePropertyPreFilterTest.java   
public void test_name_a1() throws Exception {
    SimplePropertyPreFilter filter = new SimplePropertyPreFilter("name");
    Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(a, filter));
}
项目:GitHub    文件:SimplePropertyPreFilterTest.java   
public void test_id() throws Exception {
    SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VO.class, "id");
    Assert.assertEquals("{\"id\":123}", JSON.toJSONString(vo, filter));
}
项目:GitHub    文件:SimplePropertyPreFilterTest.java   
public void test_id_0() throws Exception {
    SimplePropertyPreFilter filter = new SimplePropertyPreFilter("id");
    Assert.assertEquals("{\"id\":123}", JSON.toJSONString(vo, filter));
}
项目:GitHub    文件:SimplePropertyPreFilterTest.java   
public void test_map() throws Exception {
    SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VO.class, "name");
    String text = JSON.toJSONString(map, filter);
    Assert.assertTrue("{\"id\":123,\"name\":\"sandzhangtoo\"}".equals(text) || "{\"name\":\"sandzhangtoo\",\"id\":123}".equals(text));
}
项目:GitHub    文件:SimplePropertyPreFilterTest.java   
public void test_map_id() throws Exception {
    SimplePropertyPreFilter filter = new SimplePropertyPreFilter("id");
    Assert.assertEquals("{\"id\":123}", JSON.toJSONString(map, filter));
}
项目:GitHub    文件:SimplePropertyPreFilterTest.java   
public void test_map_name() throws Exception {
    SimplePropertyPreFilter filter = new SimplePropertyPreFilter("name");
    Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(map, filter));
}
项目:GitHub    文件:SimplePropertyPreFilterTest.java   
public void test_all() throws Exception {
    SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VO.class);
    String text = JSON.toJSONString(vo, filter);
    Assert.assertTrue("{\"id\":123,\"name\":\"sandzhangtoo\"}".equals(text) || "{\"name\":\"sandzhangtoo\",\"id\":123}".equals(text));
}
项目:GitHub    文件:SimplePropertyPreFilterTest.java   
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));
}
项目:GitHub    文件:SimplePropertyPreFilterTest.java   
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));
}
项目:GitHub    文件:SimplePropertyPreFilterTest.java   
public void test_exclude_id_map() throws Exception {
    SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VO.class);
    filter.getExcludes().add("id");
    Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(vo, filter));
}
项目:GitHub    文件:SimplePropertyPreFilterTest.java   
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));
}