use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class IntegerArrayEncodeTest method test_3_s.
public void test_3_s() throws Exception {
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
StringBuilder sb = new StringBuilder();
sb.append('[');
int len = 1000;
Integer[] array = new Integer[len];
for (int i = 0; i < array.length; ++i) {
array[i] = i;
if (i != 0) {
sb.append(',');
}
sb.append(i);
}
sb.append(']');
serializer.write(array);
Assert.assertEquals(sb.toString(), out.toString());
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class JSONSerializerDeprecatedTest method test_.
public void test_() throws Exception {
JSONSerializer ser = new JSONSerializer(new SerializeConfig());
ser.setDateFormat(new ISO8601DateFormat());
Assert.assertEquals(null, ser.getDateFormatPattern());
ser.close();
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class JSONSerializerFeatureTest method test_0.
public void test_0() throws Exception {
JSONSerializer serializer = new JSONSerializer(new SerializeWriter());
Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.QuoteFieldNames));
Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.UseSingleQuotes));
}
use of com.alibaba.fastjson.serializer.JSONSerializer 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.JSONSerializer 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());
}
Aggregations