Search in sources :

Example 66 with JSONSerializer

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

the class JSONSerializerTest method test_2_s.

public void test_2_s() throws Exception {
    JSONSerializer serializer = new JSONSerializer();
    serializer.write(Collections.EMPTY_MAP);
    Assert.assertEquals("{}", serializer.getWriter().toString());
}
Also used : JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 67 with JSONSerializer

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

the class JSONSerializerTest method test_12.

public void test_12() throws Exception {
    JSONSerializer serializer = new JSONSerializer();
    serializer.write(new Object[0]);
    Assert.assertEquals("[]", serializer.getWriter().toString());
}
Also used : JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 68 with JSONSerializer

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

the class JSONSerializerTest method test_17.

public void test_17() throws Exception {
    JSONSerializer serializer = new JSONSerializer();
    serializer.write(new Object[] { null, null, null, null });
    Assert.assertEquals("[null,null,null,null]", serializer.getWriter().toString());
}
Also used : JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 69 with JSONSerializer

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

the class JSONSerializerTest method test_0.

public void test_0() throws Exception {
    JSONSerializer serializer = new JSONSerializer();
    serializer.write(new C());
    Assert.assertEquals("[]", serializer.getWriter().toString());
}
Also used : JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 70 with JSONSerializer

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

the class JSONSerializerTest method test_error.

public void test_error() throws Exception {
    JSONException error = null;
    try {
        StringWriter out = new StringWriter();
        JSONSerializer serializer = new JSONSerializer();
        serializer.write(new JSONStreamAware() {

            public void writeJSONString(Appendable out) throws IOException {
                throw new IOException();
            }
        });
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
Also used : StringWriter(java.io.StringWriter) JSONException(com.alibaba.fastjson.JSONException) IOException(java.io.IOException) JSONStreamAware(com.alibaba.fastjson.JSONStreamAware) 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