Search in sources :

Example 31 with JSONSerializer

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

the class ListSerializerTest method test_4_s.

public void test_4_s() throws Exception {
    SerializeWriter out = new SerializeWriter();
    ListSerializer listSerializer = new ListSerializer();
    List<Object> list = new ArrayList<Object>();
    list.add(1L);
    list.add(2L);
    list.add(3L);
    list.add(Collections.emptyMap());
    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 32 with JSONSerializer

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

the class ListSerializerTest method test_5_s.

public void test_5_s() throws Exception {
    SerializeWriter out = new SerializeWriter();
    ListSerializer listSerializer = new ListSerializer();
    List<Object> list = new ArrayList<Object>();
    list.add(1L);
    list.add(21474836480L);
    list.add(null);
    list.add(Collections.emptyMap());
    list.add(21474836480L);
    listSerializer.write(new JSONSerializer(out), list, null, null, 0);
    Assert.assertEquals("[1,21474836480,null,{},21474836480]", 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 33 with JSONSerializer

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

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

use of com.alibaba.fastjson.serializer.JSONSerializer 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)

Aggregations

JSONSerializer (com.alibaba.fastjson.serializer.JSONSerializer)263 SerializeWriter (com.alibaba.fastjson.serializer.SerializeWriter)206 PropertyFilter (com.alibaba.fastjson.serializer.PropertyFilter)54 HashMap (java.util.HashMap)48 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 StringWriter (java.io.StringWriter)11 JavaBeanSerializer (com.alibaba.fastjson.serializer.JavaBeanSerializer)10 MapSerializer (com.alibaba.fastjson.serializer.MapSerializer)10 SerializeConfig (com.alibaba.fastjson.serializer.SerializeConfig)10 Map (java.util.Map)10 Date (java.util.Date)9 LinkedHashMap (java.util.LinkedHashMap)8 JSONException (com.alibaba.fastjson.JSONException)7 CollectionCodec (com.alibaba.fastjson.serializer.CollectionCodec)6 A (com.alibaba.json.bvt.serializer.filters.PropertyFilterTest.A)4 IOException (java.io.IOException)4 Color (java.awt.Color)3