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


Java JSONSerializer.write方法代码示例

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


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

示例1: toJSONString

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

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

    JSONSerializer serializer = new JSONSerializer(out);

    StringBuilder sb = new StringBuilder();
    sb.append('[');
    int len = 1000;
    int[] array = new int[len];
    for (int i = 0; i < array.length; ++i) {
        array[i] = i;
        if (i != 0) {
            sb.append(',');
        }
        sb.append(i);
    }
    sb.append(']');

    serializer.write(array);

    Assert.assertEquals(sb.toString(), out.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:IntArrayEncodeTest.java

示例3: test_valuefilter_1

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

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的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.name = "chennp2008";
    serializer.write(a);

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

示例5: test_namefilter_1

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的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_int_field.java

示例6: test_1

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的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 Boolean);
                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\":false}", text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:PropertyFilter_bool_field.java

示例7: test_namefilter_1

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的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", true);
    serializer.write(map);

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

示例8: test_2

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的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,代码来源:PropertyFilter_double.java

示例9: test_7

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

    JSONSerializer serializer = new JSONSerializer(out);
    serializer.config(SerializerFeature.UseISO8601DateFormat, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseISO8601DateFormat));
    serializer.write(new Date(1294506000000L));

    Assert.assertEquals("\"2011-01-09T01:00:00+08:00\"", out.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:DateTest.java

示例10: ser

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void ser(Blackhole bh) throws IOException {
    for (int i = 0; i < 1000; i++) {
        byteArrayOutputStream.reset();
        SerializeWriter writer = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(writer, serializeConfig);
        serializer.write(testObject);
        writer.writeToEx(byteArrayOutputStream, IOUtils.UTF8);
        serializer.close();
        bh.consume(byteArrayOutputStream);
    }
}
 
开发者ID:json-iterator,项目名称:java-benchmark,代码行数:15,代码来源:SerFastjson.java

示例11: test_namefilter

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

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

            return name;
        }

    };

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

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

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

示例12: test_2

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

    JSONSerializer serializer = new JSONSerializer(out);
    serializer.config(SerializerFeature.UseISO8601DateFormat, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseISO8601DateFormat));
    serializer.write(new Date(1294552193000L));

    Assert.assertEquals("\"2011-01-09T13:49:53+08:00\"", out.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:DateTest.java

示例13: test_0

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public void test_0() throws Exception {
    JSONSerializer serializer = new JSONSerializer();
    serializer.write(new C());

    Assert.assertEquals("[]", serializer.getWriter().toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:JSONSerializerTest.java

示例14: write

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType,
                  int features) throws IOException {
    serializer.write(((ResultCode) object).value);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:ObjectSerializerTest.java

示例15: test_1_s

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public void test_1_s() throws Exception {
    JSONSerializer serializer = new JSONSerializer();
    serializer.write(Collections.singletonList(1));

    Assert.assertEquals("[1]", serializer.getWriter().toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:JSONSerializerTest.java


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