Search in sources :

Example 6 with SimplePropertyPreFilter

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

Example 7 with SimplePropertyPreFilter

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

Example 8 with SimplePropertyPreFilter

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

Example 9 with SimplePropertyPreFilter

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

Example 10 with SimplePropertyPreFilter

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);
}
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