use of com.alibaba.fastjson.serializer.MapSerializer in project fastjson by alibaba.
the class MapSerializerTest method test_int2_s.
public void test_int2_s() throws Exception {
SerializeWriter out = new SerializeWriter();
MapSerializer mapSerializer = new MapSerializer();
Map<String, Integer> map = new LinkedHashMap<String, Integer>();
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.MapSerializer in project fastjson by alibaba.
the class MapSerializerTest method test_4.
public void test_4() throws Exception {
SerializeWriter out = new SerializeWriter();
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("TOP", "value");
map.put("bytes", new byte[] { 1, 2 });
MapSerializer mapSerializer = new MapSerializer();
mapSerializer.write(new JSONSerializer(out), map, null, null, 0);
String text = out.toString();
Assert.assertEquals("{\"TOP\":\"value\",\"bytes\":\"AQI=\"}", text);
JSONObject json = JSON.parseObject(text);
byte[] bytes = json.getBytes("bytes");
Assert.assertEquals(1, bytes[0]);
Assert.assertEquals(2, bytes[1]);
Assert.assertEquals(2, bytes.length);
}
use of com.alibaba.fastjson.serializer.MapSerializer in project fastjson by alibaba.
the class MapSerializerTest method test_special_s.
public void test_special_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.MapSerializer in project fastjson by alibaba.
the class MapSerializerTest method test_string3_s.
public void test_string3_s() throws Exception {
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.config(SerializerFeature.UseSingleQuotes, true);
MapSerializer mapSerializer = new MapSerializer();
Map<String, String> map = new LinkedHashMap<String, String>();
map.put("A", "1");
map.put("B", "2");
mapSerializer.write(serializer, map, null, null, 0);
Assert.assertEquals("{'A':'1','B':'2'}", out.toString());
}
use of com.alibaba.fastjson.serializer.MapSerializer in project fastjson by alibaba.
the class MapSerializerTest method test_long2_s.
public void test_long2_s() throws Exception {
SerializeWriter out = new SerializeWriter();
MapSerializer mapSerializer = new MapSerializer();
Map<String, Long> map = new LinkedHashMap<String, Long>();
map.put("A", 1L);
map.put("B", 2L);
mapSerializer.write(new JSONSerializer(out), map, null, null, 0);
Assert.assertEquals("{\"A\":1,\"B\":2}", out.toString());
}
Aggregations