Search in sources :

Example 96 with SerializeWriter

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

the class SerializeWriterTest_18 method test_writer_1.

public void test_writer_1() throws Exception {
    SerializeWriter out = new SerializeWriter(14);
    out.config(SerializerFeature.QuoteFieldNames, true);
    try {
        JSONSerializer serializer = new JSONSerializer(out);
        VO vo = new VO();
        vo.setValue("#");
        serializer.write(vo);
        Assert.assertEquals("{\"value\":\"#\"}", out.toString());
    } finally {
        out.close();
    }
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 97 with SerializeWriter

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

the class SerializeWriterTest_19 method test_writer_1.

public void test_writer_1() throws Exception {
    SerializeWriter out = new SerializeWriter(14);
    out.config(SerializerFeature.QuoteFieldNames, true);
    out.config(SerializerFeature.UseSingleQuotes, true);
    try {
        JSONSerializer serializer = new JSONSerializer(out);
        VO vo = new VO();
        vo.getValues().add("#");
        serializer.write(vo);
        Assert.assertEquals("{'values':['#']}", out.toString());
    } finally {
        out.close();
    }
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 98 with SerializeWriter

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

the class SerializeWriterTest_3 method test_0.

public void test_0() throws Exception {
    SerializeWriter out = new SerializeWriter(1);
    out.config(SerializerFeature.QuoteFieldNames, true);
    out.writeFieldValue(',', "name", "jobs");
    Assert.assertEquals(",\"name\":\"jobs\"", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

Example 99 with SerializeWriter

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

the class SerializeWriterTest_4 method test_5.

public void test_5() throws Exception {
    SerializeWriter out = new SerializeWriter(1000);
    out.config(SerializerFeature.QuoteFieldNames, true);
    out.config(SerializerFeature.WriteTabAsSpecial, true);
    out.writeString("\t\n \b\n\r\f\\ \"");
    Assert.assertEquals("\"\\t\\n \\b\\n\\r\\f\\\\ \\\"\"", out.toString());
    out.close();
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

Example 100 with SerializeWriter

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

the class SerializeWriterTest_4 method test_4.

public void test_4() throws Exception {
    SerializeWriter out = new SerializeWriter(1);
    out.config(SerializerFeature.QuoteFieldNames, true);
    out.config(SerializerFeature.WriteTabAsSpecial, false);
    out.writeFieldValue(',', "name", "\t\n \b\n\r\f\\ \"");
    Assert.assertEquals(",\"name\":\"\\t\\n \\b\\n\\r\\f\\\\ \\\"\"", out.toString());
    out.close();
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

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