Search in sources :

Example 6 with A

use of com.alibaba.json.bvt.serializer.filters.PropertyFilterTest.A in project fastjson by alibaba.

the class ValueFilterTest_field method test_valuefilter.

public void test_valuefilter() throws Exception {
    ValueFilter filter = new ValueFilter() {

        public Object process(Object source, String name, Object value) {
            if (name.equals("id")) {
                return "AAA";
            }
            return value;
        }
    };
    SerializeWriter out = new SerializeWriter();
    JSONSerializer serializer = new JSONSerializer(out);
    serializer.getValueFilters().add(filter);
    A a = new A();
    serializer.write(a);
    String text = out.toString();
    Assert.assertEquals("{\"id\":\"AAA\"}", text);
}
Also used : A(com.alibaba.json.bvt.serializer.filters.PropertyFilterTest.A) SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) ValueFilter(com.alibaba.fastjson.serializer.ValueFilter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Aggregations

ValueFilter (com.alibaba.fastjson.serializer.ValueFilter)6 A (com.alibaba.json.bvt.serializer.filters.PropertyFilterTest.A)6 JSONSerializer (com.alibaba.fastjson.serializer.JSONSerializer)4 SerializeWriter (com.alibaba.fastjson.serializer.SerializeWriter)4