Search in sources :

Example 51 with SerializeWriter

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

the class JSONSerializerFeatureTest method test_6_s.

public void test_6_s() throws Exception {
    JSONSerializer serializer = new JSONSerializer(new SerializeWriter());
    serializer.config(SerializerFeature.QuoteFieldNames, false);
    Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.QuoteFieldNames));
    serializer.config(SerializerFeature.UseSingleQuotes, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseSingleQuotes));
    serializer.write(Collections.singletonMap("a'ge", 33));
    Assert.assertEquals("{'a\\'ge':33}", serializer.getWriter().toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 52 with SerializeWriter

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

the class JSONSerializerFeatureTest method test_1_s.

public void test_1_s() throws Exception {
    JSONSerializer serializer = new JSONSerializer(new SerializeWriter());
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.QuoteFieldNames));
    Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.UseSingleQuotes));
    serializer.config(SerializerFeature.UseSingleQuotes, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseSingleQuotes));
    serializer.write("abc");
    Assert.assertEquals("'abc'", serializer.getWriter().toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 53 with SerializeWriter

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

the class StringArraySerializerTest method test_0.

public void test_0() throws Exception {
    SerializeWriter out = new SerializeWriter(1);
    JSONSerializer.write(out, new String[] { "a12", "b34" });
    Assert.assertEquals("[\"a12\",\"b34\"]", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

Example 54 with SerializeWriter

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

the class StringArraySerializerTest method test_1.

public void test_1() throws Exception {
    SerializeWriter out = new SerializeWriter(1);
    JSONSerializer.write(out, new String[] { "a12", "\na\nb\nc\nd\"'", "b34" });
    Assert.assertEquals("[\"a12\",\"\\na\\nb\\nc\\nd\\\"'\",\"b34\"]", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

Example 55 with SerializeWriter

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

the class StringArraySerializerTest method test_3.

public void test_3() throws Exception {
    SerializeWriter out = new SerializeWriter(1024);
    JSONSerializer.write(out, new String[] { "a12", null });
    Assert.assertEquals("[\"a12\",null]", 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