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


Java SerializeWriter类代码示例

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


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

示例1: toJSONString

import com.alibaba.fastjson.serializer.SerializeWriter; //导入依赖的package包/类
public static final String toJSONString(Object object, SerializeFilter filter, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter();
    try {
        JSONSerializer serializer = new JSONSerializer(out);
        for (SerializerFeature feature : features) {
            serializer.config(feature, true);
        }
        serializer.config(SerializerFeature.WriteDateUseDateFormat, true);
        setFilter(serializer, filter);
        serializer.write(object);
        String serializeWriter = out.toString();
        return serializeWriter;
    } finally {
        out.close();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:JSON.java

示例2: test_4

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

        public boolean apply(Object source, String name, Object value) {
            if ("name".equals(name)) {
                return false;
            }
            return true;
        }
    };

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

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

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

示例3: test_valuefilter_1

import com.alibaba.fastjson.serializer.SerializeWriter; //导入依赖的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

示例4: test_namefilter_1

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

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

            return name;
        }

    };

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

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", (byte) 0);
    serializer.write(map);

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

示例5: test_bean_3

import com.alibaba.fastjson.serializer.SerializeWriter; //导入依赖的package包/类
public void test_bean_3() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", 123);
    PO vo = TypeUtils.castToJavaBean(map, PO.class);
    Assert.assertEquals(123, vo.id);
    
    SerializeWriter out = new SerializeWriter();

    try {
        SerializeConfig config = new SerializeConfig();
        JSONSerializer serializer = new JSONSerializer(out, config);
        config.put(PO.class, new JavaBeanSerializer(PO.class, Collections.singletonMap("id", (String) null)));

        serializer.write(vo);

        Assert.assertEquals("{}", out.toString());
    } finally {
        out.close();
    }

    
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:TypeUtilsTest_castToJavaBean.java

示例6: test_0

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

        public boolean apply(Object source, String name, Object value) {
            return false;
        }
    };

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

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

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

示例7: test_namefilter_1

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

        public String process(Object source, String name, Object value) {
            if (name.equals("id")) {
                Assert.assertTrue(value instanceof Short);
                return "ID";
            }

            return name;
        }

    };

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

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", (short) 0);
    serializer.write(map);

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

示例8: test_1

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

        public boolean apply(Object source, String name, Object value) {
            if ("id".equals(name)) {
                Assert.assertTrue(value instanceof Short);
                return true;
            }
            return false;
        }
    };

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

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

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

示例9: test_0

import com.alibaba.fastjson.serializer.SerializeWriter; //导入依赖的package包/类
public void test_0() throws Exception {
    StringWriter out = new StringWriter();
    
    SerializeWriter writer = new SerializeWriter(out, 10);
    Assert.assertEquals(10, writer.getBufferLength());
    
    for (int ch = 'a'; ch <= 'z'; ++ch) {
        writer.write(ch);
    }
    writer.close();
    
    String text = out.toString();
    Assert.assertEquals(26, text.length());
    
    for (int i = 0; i < 26; ++i) {
        Assert.assertEquals(text.charAt(i), (char)('a' + i));
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:StreamWriterTest_writeChar1.java

示例10: test_1

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

        public boolean apply(Object source, String name, Object value) {
            if ("id".equals(name)) {
                Assert.assertTrue(value instanceof Float);
                return true;
            }
            return false;
        }
    };

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

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

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

示例11: test_0

import com.alibaba.fastjson.serializer.SerializeWriter; //导入依赖的package包/类
public void test_0() throws Exception {
    StringWriter out = new StringWriter();

    SerializeWriter writer = new SerializeWriter(out, 10);
    Assert.assertEquals(10, writer.getBufferLength());

    for (char ch = 'a'; ch <= 'z'; ++ch) {
        char[] chars = new char[] { ch, ch, ch };
        writer.write(chars, 0, chars.length);
    }
    writer.close();

    String text = out.toString();
    Assert.assertEquals(26 * 3, text.length());

    for (int i = 0; i < 26; ++i) {
        Assert.assertEquals(text.charAt(i * 3), (char) ('a' + i));
        Assert.assertEquals(text.charAt(i * 3 + 1), (char) ('a' + i));
        Assert.assertEquals(text.charAt(i * 3 + 2), (char) ('a' + i));
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:StreamWriterTest_writeArray.java

示例12: test_namefilter_1

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

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

            return name;
        }

    };

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

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

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

示例13: test_valuefilter

import com.alibaba.fastjson.serializer.SerializeWriter; //导入依赖的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_field.java

示例14: test_2

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

        public boolean apply(Object source, String name, Object value) {
            if ("name".equals(name)) {
                return true;
            }
            return false;
        }
    };

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

    A a = new A();
    a.setName("chennp2008");
    serializer.write(a);

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

示例15: toJSONBytes

import com.alibaba.fastjson.serializer.SerializeWriter; //导入依赖的package包/类
public static final byte[] toJSONBytes(Object object, 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.write(object);

        return out.toBytes("UTF-8");
    } finally {
        out.close();
    }
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:17,代码来源:JSON.java


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