Search in sources :

Example 26 with SerializeWriter

use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.

the class ListSerializerTest3 method test_2.

public void test_2() throws Exception {
    SerializeWriter out = new SerializeWriter();
    ListSerializer listSerializer = new ListSerializer();
    LinkedList<Object> list = new LinkedList<Object>();
    for (int i = 0; i < 100000; i++) {
        list.add(i);
    }
    long start = System.currentTimeMillis();
    listSerializer.write(new JSONSerializer(out), list, null, null, 0);
    long end = System.currentTimeMillis();
    System.out.println("linkedList time: " + (end - start));
}
Also used : ListSerializer(com.alibaba.fastjson.serializer.ListSerializer) SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) LinkedList(java.util.LinkedList) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 27 with SerializeWriter

use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.

the class ListSerializerTest3 method test_1.

public void test_1() throws Exception {
    SerializeWriter out = new SerializeWriter();
    ListSerializer listSerializer = new ListSerializer();
    ArrayList<Object> list = new ArrayList<Object>();
    for (int i = 0; i < 100000; i++) {
        list.add(i);
    }
    long start = System.currentTimeMillis();
    listSerializer.write(new JSONSerializer(out), list, null, null, 0);
    long end = System.currentTimeMillis();
    System.out.println("arrayList time: " + (end - start));
}
Also used : ListSerializer(com.alibaba.fastjson.serializer.ListSerializer) SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) ArrayList(java.util.ArrayList) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 28 with SerializeWriter

use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.

the class MapSerializerTest method test_singleton_1.

public void test_singleton_1() throws Exception {
    SerializeWriter out = new SerializeWriter();
    MapSerializer mapSerializer = new MapSerializer();
    mapSerializer.write(new JSONSerializer(out), Collections.singletonMap("A", 1), null, null, 0);
    Assert.assertEquals("{\"A\":1}", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) MapSerializer(com.alibaba.fastjson.serializer.MapSerializer) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 29 with SerializeWriter

use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.

the class ByteArraySerializerTest method test_1.

public void test_1() throws Exception {
    SerializeWriter out = new SerializeWriter(1);
    out.writeByteArray(new byte[] { 1, 2, 3 });
    Assert.assertEquals("\"AQID\"", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

Example 30 with SerializeWriter

use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.

the class CollectionSerializerTest method test_0.

public void test_0() throws Exception {
    SerializeWriter out = new SerializeWriter();
    CollectionCodec listSerializer = new CollectionCodec();
    listSerializer.write(new JSONSerializer(out), Collections.EMPTY_LIST, null, null, 0);
    Assert.assertEquals("[]", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) CollectionCodec(com.alibaba.fastjson.serializer.CollectionCodec) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Aggregations

SerializeWriter (com.alibaba.fastjson.serializer.SerializeWriter)345 JSONSerializer (com.alibaba.fastjson.serializer.JSONSerializer)206 PropertyFilter (com.alibaba.fastjson.serializer.PropertyFilter)54 HashMap (java.util.HashMap)47 StringWriter (java.io.StringWriter)38 NameFilter (com.alibaba.fastjson.serializer.NameFilter)36 ValueFilter (com.alibaba.fastjson.serializer.ValueFilter)19 ArrayList (java.util.ArrayList)12 ListSerializer (com.alibaba.fastjson.serializer.ListSerializer)11 MapSerializer (com.alibaba.fastjson.serializer.MapSerializer)10 JavaBeanSerializer (com.alibaba.fastjson.serializer.JavaBeanSerializer)8 Date (java.util.Date)8 Map (java.util.Map)8 CollectionCodec (com.alibaba.fastjson.serializer.CollectionCodec)6 SerializeConfig (com.alibaba.fastjson.serializer.SerializeConfig)6 LinkedHashMap (java.util.LinkedHashMap)6 JSONException (com.alibaba.fastjson.JSONException)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 A (com.alibaba.json.bvt.serializer.filters.PropertyFilterTest.A)4 JSONObject (com.alibaba.fastjson.JSONObject)3