use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.
the class IntArrayEncodeTest 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;
int[] array = new int[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.SerializeWriter in project fastjson by alibaba.
the class IntArrayEncodeTest method test_0_s.
public void test_0_s() throws Exception {
SerializeWriter out = new SerializeWriter(1);
JSONSerializer serializer = new JSONSerializer(out);
serializer.write(new int[] { 0, 1 });
Assert.assertEquals("[0,1]", out.toString());
}
use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.
the class IntegerArrayEncodeTest method test_4_s.
public void test_4_s() throws Exception {
SerializeWriter out = new SerializeWriter(1);
JSONSerializer serializer = new JSONSerializer(out);
serializer.write(new Integer[] { 1, null, null });
Assert.assertEquals("[1,null,null]", out.toString());
}
use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.
the class MapSerializerTest method test_special2_s.
public void test_special2_s() throws Exception {
SerializeWriter out = new SerializeWriter();
MapSerializer mapSerializer = new MapSerializer();
mapSerializer.write(new JSONSerializer(out), Collections.singletonMap("A\nB", 1), null, null, 0);
Assert.assertEquals("{\"A\\nB\":1}", out.toString());
}
use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.
the class MapSerializerTest method test_string2_s.
public void test_string2_s() throws Exception {
SerializeWriter out = new SerializeWriter();
MapSerializer mapSerializer = new MapSerializer();
Map<String, String> map = new LinkedHashMap<String, String>();
map.put("A", "1");
map.put("B", "2");
mapSerializer.write(new JSONSerializer(out), map, null, null, 0);
Assert.assertEquals("{\"A\":\"1\",\"B\":\"2\"}", out.toString());
}
Aggregations