当前位置: 首页>>代码示例>>Java>>正文


Java ValueFilter类代码示例

本文整理汇总了Java中com.alibaba.fastjson.serializer.ValueFilter的典型用法代码示例。如果您正苦于以下问题:Java ValueFilter类的具体用法?Java ValueFilter怎么用?Java ValueFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ValueFilter类属于com.alibaba.fastjson.serializer包,在下文中一共展示了ValueFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_valuefilter

import com.alibaba.fastjson.serializer.ValueFilter; //导入依赖的package包/类
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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:ValueFilterTest.java

示例2: test_valuefilter_1

import com.alibaba.fastjson.serializer.ValueFilter; //导入依赖的package包/类
public void test_valuefilter_1() throws Exception {
    ValueFilter filter = new ValueFilter() {

        public Object process(Object source, String name, Object value) {
            if (name.equals("name")) {
                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\":0,\"name\":\"AAA\"}", text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:ValueFilterTest.java

示例3: test_valuefilter_2

import com.alibaba.fastjson.serializer.ValueFilter; //导入依赖的package包/类
public void test_valuefilter_2() throws Exception {
    ValueFilter filter = new ValueFilter() {

        public Object process(Object source, String name, Object value) {
            if (name.equals("name")) {
                return "AAA";
            }

            return value;
        }

    };

    SerializeWriter out = new SerializeWriter();
    JSONSerializer serializer = new JSONSerializer(out);
    serializer.getValueFilters().add(filter);

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("name", null);
    serializer.write(map);

    String text = out.toString();
    Assert.assertEquals("{\"name\":\"AAA\"}", text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:ValueFilterTest.java

示例4: test_valuefilter_3

import com.alibaba.fastjson.serializer.ValueFilter; //导入依赖的package包/类
public void test_valuefilter_3() throws Exception {
    ValueFilter filter = new ValueFilter() {

        public Object process(Object source, String name, Object value) {
            if (name.equals("name")) {
                return null;
            }

            return value;
        }

    };

    SerializeWriter out = new SerializeWriter();
    JSONSerializer serializer = new JSONSerializer(out);
    serializer.getValueFilters().add(filter);

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("name", "AA");
    serializer.write(map);

    String text = out.toString();
    Assert.assertEquals("{}", text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:ValueFilterTest.java

示例5: test_valuefilter

import com.alibaba.fastjson.serializer.ValueFilter; //导入依赖的package包/类
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);

    Bean a = new Bean();
    serializer.write(a);

    String text = out.toString();
    Assert.assertEquals("{\"id\":\"AAA\"}", text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:ValueFilterTest_field_boolean.java

示例6: test_valuefilter_1

import com.alibaba.fastjson.serializer.ValueFilter; //导入依赖的package包/类
public void test_valuefilter_1() throws Exception {
    ValueFilter filter = new ValueFilter() {

        public Object process(Object source, String name, Object value) {
            if (name.equals("name")) {
                return "AAA";
            }

            return value;
        }

    };

    SerializeWriter out = new SerializeWriter();
    JSONSerializer serializer = new JSONSerializer(out);
    serializer.getValueFilters().add(filter);

    Bean a = new Bean();
    serializer.write(a);

    String text = out.toString();
    Assert.assertEquals("{\"id\":false,\"name\":\"AAA\"}", text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:ValueFilterTest_field_boolean.java

示例7: test_valuefilter_1

import com.alibaba.fastjson.serializer.ValueFilter; //导入依赖的package包/类
public void test_valuefilter_1() throws Exception {
    ValueFilter filter = new ValueFilter() {

        public Object process(Object source, String name, Object value) {
            if (name.equals("name")) {
                return "AAA";
            }

            return value;
        }

    };

    SerializeWriter out = new SerializeWriter();
    JSONSerializer serializer = new JSONSerializer(out);
    serializer.getValueFilters().add(filter);

    Bean a = new Bean();
    serializer.write(a);

    String text = out.toString();
    Assert.assertEquals("{\"id\":0,\"name\":\"AAA\"}", text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:ValueFilterTest_field_long.java

示例8: test_enum

import com.alibaba.fastjson.serializer.ValueFilter; //导入依赖的package包/类
public void test_enum() throws Exception {
    Model model = new Model();
    model.t1 = Type.A;
    model.t2 = null;
    
    ValueFilter valueFilter = new ValueFilter() {

        public Object process(Object object, String name, Object value) {
            return value;
        }
        
    };
    
    SerializeFilter[] filters = {valueFilter};
    String text = JSON.toJSONString(model, SerializeConfig.getGlobalInstance(), // 
                                    filters, 
                                    null,
                                    0, // 
                                    SerializerFeature.QuoteFieldNames, // 
                                    SerializerFeature.BrowserCompatible, // 
                                    SerializerFeature.WriteEnumUsingName);
    Assert.assertEquals("{\"t1\":\"A\"}", text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:EnumFieldsTest8.java

示例9: fastJsonHttpMessageConverter

import com.alibaba.fastjson.serializer.ValueFilter; //导入依赖的package包/类
private FastJsonHttpMessageConverter fastJsonHttpMessageConverter() {
    FastJsonHttpMessageConverter httpMessageConverter = new FastJsonHttpMessageConverter();
    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    fastJsonConfig.setSerializerFeatures(SerializerFeature.QuoteFieldNames,
            SerializerFeature.WriteEnumUsingToString,
            SerializerFeature.WriteMapNullValue,
            SerializerFeature.WriteDateUseDateFormat);
    fastJsonConfig.setSerializeFilters(new ValueFilter() {
        @Override
        public Object process(Object o, String s, Object source) {
            if (source == null) {
                return "";
            }
            if (source instanceof Date) {
                return ((Date) source).getTime();
            }
            return source;
        }
    });
    httpMessageConverter.setFastJsonConfig(fastJsonConfig);
    return httpMessageConverter;
}
 
开发者ID:helloworldtang,项目名称:sns-todo,代码行数:23,代码来源:WebMvcConfig.java

示例10: setFilter

import com.alibaba.fastjson.serializer.ValueFilter; //导入依赖的package包/类
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);
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:JSON.java

示例11: createFirstValueFilter

import com.alibaba.fastjson.serializer.ValueFilter; //导入依赖的package包/类
private ValueFilter createFirstValueFilter() {
    return new ValueFilter() {
        @Override
        public Object process(Object source, String name, Object value) {
            if (!(value instanceof String)) return value;

            String strValue = (String) value;
            if (bytesLen(strValue) <= 3) return value;

            String mappedValue = innerValueMapping.get(strValue);
            if (mappedValue != null) return mappedValue;

            valueBag.add(strValue);
            return value;
        }
    };
}
 
开发者ID:bingoohuang,项目名称:westjson,代码行数:18,代码来源:WestJsonThiner.java

示例12: createSecondValueFilter

import com.alibaba.fastjson.serializer.ValueFilter; //导入依赖的package包/类
public ValueFilter createSecondValueFilter() {
    // 第一遍过滤器,如果启动了值映射分析,则还需要第二个过滤器,在第一次过滤器中进行值映射分析。
    return new ValueFilter() {
        @Override
        public Object process(Object source, String name, Object value) {
            if (!(value instanceof String)) return value;

            val key = (String) value;
            if (bytesLen(key) <= 3) return key;

            String valueCode = innerValueMapping.get(key);
            if (valueCode != null) return '@' + valueCode;

            if (valueBag.count(key) <= 2) return value;

            valueCode = BaseX.base62(innerValueMapping.size());
            innerValueMapping.put(key, valueCode);
            return '@' + valueCode;
        }
    };
}
 
开发者ID:bingoohuang,项目名称:westjson,代码行数:22,代码来源:WestJsonThiner.java

示例13: test_toJSONString

import com.alibaba.fastjson.serializer.ValueFilter; //导入依赖的package包/类
public void test_toJSONString() throws Exception {
    ValueFilter filter = new ValueFilter() {

        public Object process(Object source, String name, Object value) {
            if (name.equals("id")) {
                return "AAA";
            }

            return value;
        }

    };
    
    Assert.assertEquals("{\"id\":\"AAA\"}", JSON.toJSONString(new A(), filter));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:ValueFilterTest.java

示例14: test_toJSONString

import com.alibaba.fastjson.serializer.ValueFilter; //导入依赖的package包/类
public void test_toJSONString() throws Exception {
    ValueFilter filter = new ValueFilter() {

        public Object process(Object source, String name, Object value) {
            if (name.equals("id")) {
                return "AAA";
            }

            return value;
        }

    };
    
    Assert.assertEquals("{\"id\":\"AAA\"}", JSON.toJSONString(new Bean(), filter));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:ValueFilterTest_field_boolean.java

示例15: test_enum

import com.alibaba.fastjson.serializer.ValueFilter; //导入依赖的package包/类
public void test_enum() throws Exception {
    Model model = new Model();
    model.t1 = Type.A;
    model.t2 = null;

    ValueFilter filter = new ValueFilter() {
        public Object process(Object object, String name, Object value) {
            return null;
        }
    };
    String text = JSON.toJSONString(model, filter, SerializerFeature.WriteMapNullValue);
    Assert.assertEquals("{\"t1\":null,\"t2\":null}", text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:EnumFieldsTest7.java


注:本文中的com.alibaba.fastjson.serializer.ValueFilter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。