Search in sources :

Example 6 with ListSerializer

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

the class ListSerializerTest2 method test_0.

public void test_0() throws Exception {
    SerializeWriter out = new SerializeWriter();
    ListSerializer listSerializer = new ListSerializer();
    Object[] array = new Object[] { 1, 2, 3L, 4L, 5, 6, "a" };
    List<Object> list = Arrays.asList(array);
    listSerializer.write(new JSONSerializer(out), list, null, null, 0);
    // System.out.println(out.toString());
    Assert.assertEquals("[1,2,3,4,5,6,\"a\"]", out.toString());
}
Also used : ListSerializer(com.alibaba.fastjson.serializer.ListSerializer) SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 7 with ListSerializer

use of com.alibaba.fastjson.serializer.ListSerializer 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 8 with ListSerializer

use of com.alibaba.fastjson.serializer.ListSerializer 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 9 with ListSerializer

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

the class ListSerializerTest method test_3_s.

public void test_3_s() throws Exception {
    SerializeWriter out = new SerializeWriter();
    ListSerializer listSerializer = new ListSerializer();
    List<Object> list = new ArrayList<Object>();
    list.add(1);
    list.add(2);
    list.add(3);
    listSerializer.write(new JSONSerializer(out), list, null, null, 0);
    Assert.assertEquals("[1,2,3]", out.toString());
}
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 10 with ListSerializer

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

the class ListSerializerTest method test_0_s.

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

Aggregations

JSONSerializer (com.alibaba.fastjson.serializer.JSONSerializer)11 ListSerializer (com.alibaba.fastjson.serializer.ListSerializer)11 SerializeWriter (com.alibaba.fastjson.serializer.SerializeWriter)11 ArrayList (java.util.ArrayList)8 LinkedList (java.util.LinkedList)1