當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。