@Test
    public void testCompatible() throws Exception {
        SimpleMapSerializer simpleMapSerializer = new SimpleMapSerializer();

        HashMap<String, String> map = new HashMap<String, String>();
        map.put("1", "2");
        map.put("", "x");
        map.put("b", null);
        map.put(null, null);
        byte[] bs = simpleMapSerializer.encode(map);
        Map<String, String> readMap = simpleMapSerializer.decode(bs);
        Assert.assertEquals(2, readMap.size());

        UnsafeByteArrayOutputStream out = new UnsafeByteArrayOutputStream(64);

        //key is null
        simpleMapSerializer.writeString(out, null);
        simpleMapSerializer.writeString(out, "value");

        //value is null
        simpleMapSerializer.writeString(out, "value");
        simpleMapSerializer.writeString(out, null);

        //value is null and key is null
        simpleMapSerializer.writeString(out, null);
        simpleMapSerializer.writeString(out, null);

        //value is not null and key is not null
        simpleMapSerializer.writeString(out, "key");
        simpleMapSerializer.writeString(out, "value");

        readMap = simpleMapSerializer.decode(out.toByteArray());
        Assert.assertEquals(1, readMap.size());
        Assert.assertEquals("value", readMap.get("key"));
    }
@author <a href="mailto:zhanggeng.zg@antfin.com">GengZhang</a>
remoting/remoting-bolt/src/test/java/com/alipay/sofa/rpc/codec/bolt/SimpleMapSerializerTest.java