Search in sources :

Example 76 with SerializeWriter

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

the class SerializeWriterTest_12 method test_erro_0.

public void test_erro_0() throws Exception {
    SerializeWriter out = new SerializeWriter(new ErrorWriter());
    Exception error = null;
    try {
        out.flush();
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
    out.close();
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) IOException(java.io.IOException)

Example 77 with SerializeWriter

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

the class SerializeWriterTest_13 method test_writer.

public void test_writer() throws Exception {
    SerializeWriter out = new SerializeWriter(3);
    try {
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.write(Collections.singletonMap("", ""));
        Assert.assertEquals("{\"\":\"\"}", out.toString());
    } finally {
        out.close();
    }
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 78 with SerializeWriter

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

the class SerializeWriterTest_13 method test_writer_single.

public void test_writer_single() throws Exception {
    SerializeWriter out = new SerializeWriter(3);
    out.config(SerializerFeature.UseSingleQuotes, true);
    try {
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.write(Collections.singletonMap("", ""));
        Assert.assertEquals("{'':''}", out.toString());
    } finally {
        out.close();
    }
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 79 with SerializeWriter

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

the class SerializeWriterTest_14 method test_writer_3.

public void test_writer_3() throws Exception {
    StringWriter strOut = new StringWriter();
    SerializeWriter out = new SerializeWriter(strOut, 1);
    try {
        JSONSerializer serializer = new JSONSerializer(out);
        Map map = Collections.singletonMap("ab\t", "a");
        serializer.write(map);
    } finally {
        out.close();
    }
    Assert.assertEquals("{\"ab\\t\":\"a\"}", strOut.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) StringWriter(java.io.StringWriter) Map(java.util.Map) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 80 with SerializeWriter

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

the class SerializeWriterTest_15 method test_writer_3.

public void test_writer_3() throws Exception {
    StringWriter strOut = new StringWriter();
    SerializeWriter out = new SerializeWriter(strOut, 1);
    out.config(SerializerFeature.UseSingleQuotes, true);
    try {
        JSONSerializer serializer = new JSONSerializer(out);
        Map map = Collections.singletonMap("ab\t", "a");
        serializer.write(map);
    } finally {
        out.close();
    }
    Assert.assertEquals("{'ab\\t':'a'}", strOut.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) StringWriter(java.io.StringWriter) Map(java.util.Map) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Aggregations

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