@Override
public <K, V> void testMap(Map<K, V> v, Class<K> keyElementClass, Class<V> valueElementClass) throws Exception {
MessagePack msgpack = new JSON();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
if (v == null) {
packer.writeNil();
} else {
packer.writeMapBegin(v.size());
for (Map.Entry<Object, Object> e : ((Map<Object, Object>) v).entrySet()) {
if (!(e.getKey() instanceof String)) {
try {
packer.write(e.getKey());
fail("JSONPacker should reject non-String value for the map key");
} catch (IOException ex) {
assertTrue(ex instanceof IOException);
}
return;
}
packer.write(e.getKey());
packer.write(e.getValue());
}
packer.writeMapEnd();
}
byte[] bytes = out.toByteArray();
Unpacker unpacker = msgpack.createBufferUnpacker(bytes);
if (unpacker.trySkipNil()) {
assertEquals(null, v);