Search in sources :

Example 11 with SimplePropertyPreFilter

use of com.alibaba.fastjson.serializer.SimplePropertyPreFilter in project fastjson by alibaba.

the class Issue763 method test_0.

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

Example 12 with SimplePropertyPreFilter

use of com.alibaba.fastjson.serializer.SimplePropertyPreFilter in project fastjson by alibaba.

the class SimplePropertyPreFilterTest method test_name_a1.

public void test_name_a1() throws Exception {
    SimplePropertyPreFilter filter = new SimplePropertyPreFilter("name");
    Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(a, filter));
}
Also used : SimplePropertyPreFilter(com.alibaba.fastjson.serializer.SimplePropertyPreFilter)

Example 13 with SimplePropertyPreFilter

use of com.alibaba.fastjson.serializer.SimplePropertyPreFilter in project fastjson by alibaba.

the class SimplePropertyPreFilterTest method test_map.

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

Example 14 with SimplePropertyPreFilter

use of com.alibaba.fastjson.serializer.SimplePropertyPreFilter in project fastjson by alibaba.

the class SimplePropertyPreFilterTest method test_id_0.

public void test_id_0() throws Exception {
    SimplePropertyPreFilter filter = new SimplePropertyPreFilter("id");
    Assert.assertEquals("{\"id\":123}", JSON.toJSONString(vo, filter));
}
Also used : SimplePropertyPreFilter(com.alibaba.fastjson.serializer.SimplePropertyPreFilter)

Example 15 with SimplePropertyPreFilter

use of com.alibaba.fastjson.serializer.SimplePropertyPreFilter in project fastjson by alibaba.

the class SimplePropertyPreFilterTest method test_name_a.

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));
}
Also used : 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