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

项目:boohee_v5.6    文件:JSON.java   
private static void setFilter(JSONSerializer serializer, SerializeFilter filter) {
    if (filter != null) {
        if (filter instanceof PropertyPreFilter) {
            serializer.getPropertyPreFilters().add((PropertyPreFilter) filter);
        }
        if (filter instanceof NameFilter) {
            serializer.getNameFilters().add((NameFilter) filter);
        }
        if (filter instanceof ValueFilter) {
            serializer.getValueFilters().add((ValueFilter) filter);
        }
        if (filter instanceof PropertyFilter) {
            serializer.getPropertyFilters().add((PropertyFilter) filter);
        }
        if (filter instanceof BeforeFilter) {
            serializer.getBeforeFilters().add((BeforeFilter) filter);
        }
        if (filter instanceof AfterFilter) {
            serializer.getAfterFilters().add((AfterFilter) filter);
        }
    }
}
项目:GitHub    文件:AfterFilterTest3.java   
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}");
}
项目:GitHub    文件:AfterFilterTest3.java   
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\"}");
}
项目:GitHub    文件:AfterFilterTest.java   
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));
}
项目:GitHub    文件:AfterFilterTest.java   
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("{\"id\":123,\"name\":\"wenshao\"}", JSON.toJSONString(new VO(), filter));
}
项目:GitHub    文件:AfterFilterTest2.java   
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));
}
项目:GitHub    文件:AfterFilterTest2.java   
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("{\"id\":123,\"name\":\"wenshao\"}", JSON.toJSONString(new VO(), filter));
}
项目:uavstack    文件:JSON.java   
private static void setFilter(JSONSerializer serializer, SerializeFilter filter) {
    if (filter == null) {
        return;
    }

    if (filter instanceof PropertyPreFilter) {
        serializer.getPropertyPreFilters().add((PropertyPreFilter) filter);
    }

    if (filter instanceof NameFilter) {
        serializer.getNameFilters().add((NameFilter) filter);
    }

    if (filter instanceof ValueFilter) {
        serializer.getValueFilters().add((ValueFilter) filter);
    }

    if (filter instanceof PropertyFilter) {
        serializer.getPropertyFilters().add((PropertyFilter) filter);
    }

    if (filter instanceof BeforeFilter) {
        serializer.getBeforeFilters().add((BeforeFilter) filter);
    }

    if (filter instanceof AfterFilter) {
        serializer.getAfterFilters().add((AfterFilter) filter);
    }
}
项目:itmarry    文件:JSON.java   
public static final String toJSONString(Object object, SerializeFilter filter, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter();

    try {
        JSONSerializer serializer = new JSONSerializer(out);
        for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) {
            serializer.config(feature, true);
        }

        serializer.config(SerializerFeature.WriteDateUseDateFormat, true);

        if (filter != null) {
            if (filter instanceof PropertyPreFilter) {
                serializer.getPropertyPreFilters().add((PropertyPreFilter) filter);
            }

            if (filter instanceof NameFilter) {
                serializer.getNameFilters().add((NameFilter) filter);
            }

            if (filter instanceof ValueFilter) {
                serializer.getValueFilters().add((ValueFilter) filter);
            }

            if (filter instanceof PropertyFilter) {
                serializer.getPropertyFilters().add((PropertyFilter) filter);
            }

            if (filter instanceof BeforeFilter) {
                serializer.getBeforeFilters().add((BeforeFilter) filter);
            }

            if (filter instanceof AfterFilter) {
                serializer.getAfterFilters().add((AfterFilter) filter);
            }
        }

        serializer.write(object);

        return out.toString();
    } finally {
        out.close();
    }
}