use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class SerializeWriterTest_15 method test_writer_1.
@SuppressWarnings("rawtypes")
public void test_writer_1() 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("", "a");
serializer.write(map);
} finally {
out.close();
}
Assert.assertEquals("{'':'a'}", strOut.toString());
}
use of com.alibaba.fastjson.serializer.JSONSerializer 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();
}
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class ObjectWriteTest method test_objectWriteTest.
public void test_objectWriteTest() throws Exception {
ObjectSerializer serializer = SerializeConfig.getGlobalInstance().getObjectWriter(Model.class);
JSONSerializer jsonSerializer = new JSONSerializer();
serializer.write(jsonSerializer, null, "a", Model.class, 0);
String text = jsonSerializer.out.toString();
assertEquals("null", text);
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class PascalNameFilterTest method test_0.
public void test_0() throws Exception {
JSONSerializer serializer = new JSONSerializer();
serializer.getNameFilters().add(new PascalNameFilter());
VO vo = new VO();
vo.setId(123);
vo.setName("wenshao");
serializer.write(vo);
Assert.assertEquals("{\"Id\":123,\"Name\":\"wenshao\"}", serializer.toString());
serializer.close();
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class SerializeWriterTest_16 method test_writer_1.
public void test_writer_1() throws Exception {
StringWriter strOut = new StringWriter();
SerializeWriter out = new SerializeWriter(strOut, 14);
out.config(SerializerFeature.BrowserCompatible, true);
try {
JSONSerializer serializer = new JSONSerializer(out);
VO vo = new VO();
vo.setValue("abcd\t");
serializer.write(vo);
} finally {
out.close();
}
Assert.assertEquals("{value:\"abcd\\t\"}", strOut.toString());
}
Aggregations