use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class StringSerializerTest method test_3.
public void test_3() throws Exception {
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.config(SerializerFeature.UseSingleQuotes, true);
serializer.write(new TestEntity("张三"));
Assert.assertEquals("{'value':'张三'}", out.toString());
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class SerializeWriterTest_13 method test_writer.
public void test_writer() throws Exception {
SerializeWriter out = new SerializeWriter(3);
try {
JSONSerializer serializer = new JSONSerializer(out);
serializer.write(Collections.singletonMap("", ""));
Assert.assertEquals("{\"\":\"\"}", out.toString());
} finally {
out.close();
}
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class SerializeWriterTest_13 method test_writer_single.
public void test_writer_single() throws Exception {
SerializeWriter out = new SerializeWriter(3);
out.config(SerializerFeature.UseSingleQuotes, true);
try {
JSONSerializer serializer = new JSONSerializer(out);
serializer.write(Collections.singletonMap("", ""));
Assert.assertEquals("{'':''}", out.toString());
} finally {
out.close();
}
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class SerializeWriterTest_14 method test_writer_3.
public void test_writer_3() throws Exception {
StringWriter strOut = new StringWriter();
SerializeWriter out = new SerializeWriter(strOut, 1);
try {
JSONSerializer serializer = new JSONSerializer(out);
Map map = Collections.singletonMap("ab\t", "a");
serializer.write(map);
} finally {
out.close();
}
Assert.assertEquals("{\"ab\\t\":\"a\"}", strOut.toString());
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class SerializeWriterTest_15 method test_writer_3.
public void test_writer_3() 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("ab\t", "a");
serializer.write(map);
} finally {
out.close();
}
Assert.assertEquals("{'ab\\t':'a'}", strOut.toString());
}
Aggregations