use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.
the class JSONSerializerFeatureTest method test_4_s.
public void test_4_s() throws Exception {
JSONSerializer serializer = new JSONSerializer(new SerializeWriter());
serializer.config(SerializerFeature.QuoteFieldNames, false);
Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.QuoteFieldNames));
serializer.write(Collections.singletonMap("a\nge", 33));
Assert.assertEquals("{\"a\\nge\":33}", serializer.getWriter().toString());
}
use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.
the class JSONSerializerFeatureTest method test_6.
public void test_6() 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_2.
public void test_2() throws Exception {
JSONSerializer serializer = new JSONSerializer(new SerializeWriter());
serializer.config(SerializerFeature.UseSingleQuotes, true);
Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseSingleQuotes));
serializer.write(Collections.singletonMap("age", 33));
Assert.assertEquals("{'age':33}", serializer.getWriter().toString());
}
use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.
the class JSONSerializerFeatureTest method test_2_s.
public void test_2_s() throws Exception {
JSONSerializer serializer = new JSONSerializer(new SerializeWriter());
serializer.config(SerializerFeature.UseSingleQuotes, true);
Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseSingleQuotes));
serializer.write(Collections.singletonMap("age", 33));
Assert.assertEquals("{'age':33}", serializer.getWriter().toString());
}
use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.
the class JSONSerializerFeatureTest method test_1.
public void test_1() 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());
}
Aggregations