Search in sources :

Example 1 with ListSerializer

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

the class ListSerializerTest method test_8_s.

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

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

the class ListSerializerTest method test_2_s.

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

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

the class ListSerializerTest method test_7_s.

public void test_7_s() throws Exception {
    SerializeWriter out = new SerializeWriter(SerializerFeature.BrowserCompatible, SerializerFeature.WriteClassName);
    ListSerializer listSerializer = new ListSerializer();
    List<Object> list = new ArrayList<Object>();
    list.add(1L);
    list.add(1453964515792017682L);
    listSerializer.write(new JSONSerializer(out), list, null, null, 0);
    Assert.assertEquals("[1L,1453964515792017682L]", 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 4 with ListSerializer

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

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

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