Search in sources :

Example 86 with SerializeWriter

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

the class SerializeWriterTest_7 method test_3.

public void test_3() throws Exception {
    SerializeWriter out = new SerializeWriter(1);
    out.config(SerializerFeature.QuoteFieldNames, false);
    out.writeFieldName("a\n\n\n\n");
    Assert.assertEquals("\"a\\n\\n\\n\\n\":", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

Example 87 with SerializeWriter

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

the class SerializeWriterTest_7 method test_0.

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

Example 88 with SerializeWriter

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

the class SerializeWriterTest_7 method test_1.

public void test_1() throws Exception {
    SerializeWriter out = new SerializeWriter(1);
    out.config(SerializerFeature.QuoteFieldNames, true);
    out.config(SerializerFeature.UseSingleQuotes, true);
    out.writeFieldName("名称");
    Assert.assertEquals("'名称':", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

Example 89 with SerializeWriter

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

the class SerializeWriterTest_8 method test_singleQuote.

public void test_singleQuote() throws Exception {
    StringBuilder buf = new StringBuilder();
    for (int i = 0; i < 1024; ++i) {
        buf.append('a');
    }
    buf.append("中国");
    buf.append("\0");
    SerializeWriter out = new SerializeWriter(new StringWriter());
    try {
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.config(SerializerFeature.QuoteFieldNames, false);
        serializer.config(SerializerFeature.UseSingleQuotes, true);
        serializer.write(Collections.singletonMap(buf.toString(), ""));
    } finally {
        out.close();
    }
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) StringWriter(java.io.StringWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 90 with SerializeWriter

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

the class SerializeWriterTest_9 method test_error.

public void test_error() throws Exception {
    SerializeWriter writer = new SerializeWriter(new StringWriter());
    Exception error = null;
    try {
        writer.writeTo(new StringWriter());
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
    writer.close();
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) StringWriter(java.io.StringWriter)

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