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

项目: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    文件:BeforeFilterTest3.java   
public void test_beforeFilter() throws Exception {
    BeforeFilter filter = new BeforeFilter() {

        @Override
        public void writeBefore(Object object) {
            this.writeKeyValue("id", 123);
        }
    };
    Assert.assertEquals(JSON.toJSONString(new VO(), filter), "{\"id\":123,\"value\":1001}");
}
项目:GitHub    文件:BeforeFilterTest3.java   
public void test_beforeFilter2() throws Exception {
    BeforeFilter filter = new BeforeFilter() {

        @Override
        public void writeBefore(Object object) {
            this.writeKeyValue("id", 123);
            this.writeKeyValue("name", "wenshao");
        }
    };
    Assert.assertEquals(JSON.toJSONString(new VO(), filter), "{\"id\":123,\"name\":\"wenshao\",\"value\":1001}");
}
项目:GitHub    文件:BeforeFilterTest.java   
public void test_beforeFilter() throws Exception {
    BeforeFilter filter = new BeforeFilter() {

        @Override
        public void writeBefore(Object object) {
            this.writeKeyValue("id", 123);
        }
    };
    Assert.assertEquals("{\"id\":123}",JSON.toJSONString( new VO(), filter));
}
项目:GitHub    文件:BeforeFilterTest.java   
public void test_beforeFilter2() throws Exception {
    BeforeFilter filter = new BeforeFilter() {

        @Override
        public void writeBefore(Object object) {
            this.writeKeyValue("id", 123);
            this.writeKeyValue("name", "wenshao");
        }
    };
    Assert.assertEquals("{\"id\":123,\"name\":\"wenshao\"}", JSON.toJSONString(new VO(), filter));
}
项目:GitHub    文件:BeforeFilterTest2.java   
public void test_beforeFilter() throws Exception {
    BeforeFilter filter = new BeforeFilter() {

        @Override
        public void writeBefore(Object object) {
            this.writeKeyValue("id", 123);
        }
    };
    Assert.assertEquals(JSON.toJSONString(new VO(), filter), "{\"id\":123}");
}
项目:GitHub    文件:BeforeFilterTest2.java   
public void test_beforeFilter2() throws Exception {
    BeforeFilter filter = new BeforeFilter() {

        @Override
        public void writeBefore(Object object) {
            this.writeKeyValue("id", 123);
            this.writeKeyValue("name", "wenshao");
        }
    };
    Assert.assertEquals(JSON.toJSONString(new VO(), filter), "{\"id\":123,\"name\":\"wenshao\"}");
}
项目: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();
    }
}