Search in sources :

Example 21 with SerializeWriter

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

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

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

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

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

Aggregations

SerializeWriter (com.alibaba.fastjson.serializer.SerializeWriter)344 JSONSerializer (com.alibaba.fastjson.serializer.JSONSerializer)205 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