Search in sources :

Example 56 with SerializeWriter

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

the class StringSerializerTest method test_10_d.

public void test_10_d() throws Exception {
    SerializeWriter out = new SerializeWriter();
    out.writeFieldName("123\na\nb\nc\nd\"'e", true);
    Assert.assertEquals("\"123\\na\\nb\\nc\\nd\\\"'e\":", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

Example 57 with SerializeWriter

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

the class StringSerializerTest method test_14.

public void test_14() throws Exception {
    SerializeWriter out = new SerializeWriter(4);
    out.config(SerializerFeature.UseSingleQuotes, false);
    out.writeString("1\"");
    Assert.assertEquals("\"1\\\"\"", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

Example 58 with SerializeWriter

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

the class StringSerializerTest method test_3.

public void test_3() throws Exception {
    SerializeWriter out = new SerializeWriter();
    JSONSerializer serializer = new JSONSerializer(out);
    serializer.config(SerializerFeature.UseSingleQuotes, true);
    serializer.write(new TestEntity("张三"));
    Assert.assertEquals("{'value':'张三'}", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 59 with SerializeWriter

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

the class StringSerializerTest method test_6.

public void test_6() throws Exception {
    SerializeWriter out = new SerializeWriter(1);
    out.config(SerializerFeature.UseSingleQuotes, true);
    out.writeString(null);
    Assert.assertEquals("null", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

Example 60 with SerializeWriter

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

the class StringSerializerTest method test_10.

public void test_10() throws Exception {
    SerializeWriter out = new SerializeWriter();
    out.config(SerializerFeature.UseSingleQuotes, true);
    out.writeFieldName("123\na\nb\nc\nd\"'e");
    Assert.assertEquals("'123\\na\\nb\\nc\\nd\"\\'e':", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

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