Search in sources :

Example 1 with MapSerializer

use of com.alibaba.fastjson.serializer.MapSerializer in project fastjson by alibaba.

the class MapSerializerTest method test_singleton_1.

public void test_singleton_1() throws Exception {
    SerializeWriter out = new SerializeWriter();
    MapSerializer mapSerializer = new MapSerializer();
    mapSerializer.write(new JSONSerializer(out), Collections.singletonMap("A", 1), null, null, 0);
    Assert.assertEquals("{\"A\":1}", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) MapSerializer(com.alibaba.fastjson.serializer.MapSerializer) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 2 with MapSerializer

use of com.alibaba.fastjson.serializer.MapSerializer 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());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) MapSerializer(com.alibaba.fastjson.serializer.MapSerializer) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 3 with MapSerializer

use of com.alibaba.fastjson.serializer.MapSerializer 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());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) MapSerializer(com.alibaba.fastjson.serializer.MapSerializer) LinkedHashMap(java.util.LinkedHashMap) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 4 with MapSerializer

use of com.alibaba.fastjson.serializer.MapSerializer 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());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) MapSerializer(com.alibaba.fastjson.serializer.MapSerializer) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 5 with MapSerializer

use of com.alibaba.fastjson.serializer.MapSerializer in project fastjson by alibaba.

the class MapSerializerTest method test_special3_s.

public void test_special3_s() throws Exception {
    SerializeWriter out = new SerializeWriter();
    MapSerializer mapSerializer = new MapSerializer();
    mapSerializer.write(new JSONSerializer(out), Collections.singletonMap("A\nB", Collections.EMPTY_MAP), null, null, 0);
    Assert.assertEquals("{\"A\\nB\":{}}", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) MapSerializer(com.alibaba.fastjson.serializer.MapSerializer) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Aggregations

JSONSerializer (com.alibaba.fastjson.serializer.JSONSerializer)10 MapSerializer (com.alibaba.fastjson.serializer.MapSerializer)10 SerializeWriter (com.alibaba.fastjson.serializer.SerializeWriter)10 LinkedHashMap (java.util.LinkedHashMap)5 JSONObject (com.alibaba.fastjson.JSONObject)1