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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations