Package com.alibaba.fastjson.serializer

Examples of com.alibaba.fastjson.serializer.MapSerializer


public class MapSerializerTest extends TestCase {

    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);

        Assert.assertEquals("{}", out.toString());
    }
View Full Code Here


    }

    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);

        Assert.assertEquals("{\"A\":1}", out.toString());
    }
View Full Code Here

    }

    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);

        Assert.assertEquals("{\"A\":1,\"B\":2}", out.toString());
    }
View Full Code Here

    }

    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);

        Assert.assertEquals("{\"A\":1,\"B\":2}", out.toString());
    }
View Full Code Here

    }

    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);

        Assert.assertEquals("{\"A\":\"1\",\"B\":\"2\"}", out.toString());
    }
View Full Code Here

        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);

        Assert.assertEquals("{'A':'1','B':'2'}", out.toString());
    }
View Full Code Here

    }

    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);

        Assert.assertEquals("{\"A\\nB\":1}", out.toString());
    }
View Full Code Here

    }

    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);

        Assert.assertEquals("{\"A\\nB\":1}", out.toString());
    }
View Full Code Here

    }

    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);

        Assert.assertEquals("{\"A\\nB\":{}}", out.toString());
    }
View Full Code Here

        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);

        String text = out.toString();
        Assert.assertEquals("{\"TOP\":\"value\",\"bytes\":\"AQI=\"}", text);
       
        JSONObject json = JSON.parseObject(text);
View Full Code Here

TOP

Related Classes of com.alibaba.fastjson.serializer.MapSerializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.