Search in sources :

Example 81 with SerializeWriter

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

the class SerializeWriterTest_15 method test_writer_1.

@SuppressWarnings("rawtypes")
public void test_writer_1() 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("", "a");
        serializer.write(map);
    } finally {
        out.close();
    }
    Assert.assertEquals("{'':'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 82 with SerializeWriter

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

the class SerializeWriterTest_4 method test_0.

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

Example 83 with SerializeWriter

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

the class SerializeWriterTest_5 method test_3.

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

Example 84 with SerializeWriter

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

the class SerializeWriterTest_5 method test_0.

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

Example 85 with SerializeWriter

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

the class SerializeWriterTest_7 method test_2.

public void test_2() throws Exception {
    SerializeWriter out = new SerializeWriter(1);
    out.config(SerializerFeature.QuoteFieldNames, false);
    out.writeFieldName("名称");
    Assert.assertEquals("名称:", 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