Search in sources :

Example 36 with JSONSerializer

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

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

Example 38 with JSONSerializer

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

the class CollectionSerializerTest method test_4_s.

public void test_4_s() throws Exception {
    SerializeWriter out = new SerializeWriter();
    CollectionCodec listSerializer = new CollectionCodec();
    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 : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) CollectionCodec(com.alibaba.fastjson.serializer.CollectionCodec) ArrayList(java.util.ArrayList) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 39 with JSONSerializer

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

the class CollectionSerializerTest method test_1.

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

Example 40 with JSONSerializer

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

the class CollectionSerializerTest method test_5_s.

public void test_5_s() throws Exception {
    SerializeWriter out = new SerializeWriter();
    CollectionCodec listSerializer = new CollectionCodec();
    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 : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) CollectionCodec(com.alibaba.fastjson.serializer.CollectionCodec) 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