use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.
the class SerializeWriterTest_12 method test_erro_0.
public void test_erro_0() throws Exception {
SerializeWriter out = new SerializeWriter(new ErrorWriter());
Exception error = null;
try {
out.flush();
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
out.close();
}
use of com.alibaba.fastjson.serializer.SerializeWriter 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.SerializeWriter 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.SerializeWriter 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.SerializeWriter 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