use of com.alibaba.fastjson.serializer.JSONSerializer 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.JSONSerializer 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());
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class MapSerializerTest method test_empty_1.
public void test_empty_1() throws Exception {
SerializeWriter out = new SerializeWriter();
MapSerializer mapSerializer = new MapSerializer();
mapSerializer.write(new JSONSerializer(out), Collections.EMPTY_MAP, null, null, 0);
Assert.assertEquals("{}", out.toString());
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class MapTest method toJSONString.
public static final String toJSONString(Object object) {
SerializeWriter out = new SerializeWriter();
try {
JSONSerializer serializer = new JSONSerializer(out);
serializer.config(SerializerFeature.SortField, false);
serializer.config(SerializerFeature.UseSingleQuotes, true);
serializer.write(object);
return out.toString();
} catch (StackOverflowError e) {
throw new JSONException("maybe circular references", e);
} finally {
out.close();
}
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class IntegerArrayEncodeTest method test_1_s.
public void test_1_s() throws Exception {
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.write(new Integer[] {});
Assert.assertEquals("[]", out.toString());
}
Aggregations