Search in sources :

Example 6 with AfterFilter

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

the class AfterFilterTest2 method test_afterFilter.

public void test_afterFilter() throws Exception {
    AfterFilter filter = new AfterFilter() {

        @Override
        public void writeAfter(Object object) {
            this.writeKeyValue("id", 123);
        }
    };
    Assert.assertEquals("{\"id\":123}", JSON.toJSONString(new VO(), filter));
}
Also used : AfterFilter(com.alibaba.fastjson.serializer.AfterFilter)

Example 7 with AfterFilter

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

the class AfterFilterTest3 method test_afterFilter2.

public void test_afterFilter2() throws Exception {
    AfterFilter filter = new AfterFilter() {

        @Override
        public void writeAfter(Object object) {
            this.writeKeyValue("id", 123);
            this.writeKeyValue("name", "wenshao");
        }
    };
    Assert.assertEquals(JSON.toJSONString(new VO(), filter), "{\"value\":1001,\"id\":123,\"name\":\"wenshao\"}");
}
Also used : AfterFilter(com.alibaba.fastjson.serializer.AfterFilter)

Example 8 with AfterFilter

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

the class AfterFilterTest3 method test_afterFilter.

public void test_afterFilter() throws Exception {
    AfterFilter filter = new AfterFilter() {

        @Override
        public void writeAfter(Object object) {
            this.writeKeyValue("id", 123);
        }
    };
    Assert.assertEquals(JSON.toJSONString(new VO(), filter), "{\"value\":1001,\"id\":123}");
}
Also used : AfterFilter(com.alibaba.fastjson.serializer.AfterFilter)

Aggregations

AfterFilter (com.alibaba.fastjson.serializer.AfterFilter)8 SerializeConfig (com.alibaba.fastjson.serializer.SerializeConfig)2