use of com.alibaba.fastjson.serializer.JSONSerializer 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.JSONSerializer 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.JSONSerializer in project fastjson by alibaba.
the class JSONSerializerTest method test_10.
public void test_10() throws Exception {
JSONSerializer serializer = new JSONSerializer();
serializer.write(3);
Assert.assertEquals("3", serializer.getWriter().toString());
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class JSONSerializerTest method test_2.
public void test_2() throws Exception {
JSONSerializer serializer = new JSONSerializer();
serializer.write(Collections.EMPTY_MAP);
Assert.assertEquals("{}", serializer.getWriter().toString());
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class JSONSerializerTest method test_5_null.
public void test_5_null() throws Exception {
JSONSerializer serializer = new JSONSerializer();
serializer.config(SerializerFeature.WriteMapNullValue, true);
serializer.write(new A(null));
Assert.assertEquals("{\"id\":null}", serializer.getWriter().toString());
}
Aggregations