SimpleSerialization implements Serialization { @Override public byte[] serialize(Object obj) throws IOException { GrowableByteBuffer buffer = new GrowableByteBuffer(4096); serialize(obj, buffer); buffer.flip(); byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; }  static boolean isStringCollection(Collection<?> obj); static boolean isStringMap(Map<?, ?> obj); @Override byte[] serialize(Object obj); @Override T deserialize(byte[] bytes, Class<T> clz); @Override byte[] serializeMulti(Object[] data); @Override Object[] deserializeMulti(byte[] data, Class<?>[] classes); @Override int getSerializationNumber();  }
@Test public void serialize() throws Exception { String s = "hello"; SimpleSerialization serialization = new SimpleSerialization(); byte[] b = serialization.serialize(s); assertNotNull(b); assertTrue(b.length > 0); String result = serialization.deserialize(b, String.class); assertEquals(s, result); Map<String, String> map = new HashMap<String, String>(); map.put("name", "ray"); map.put("code", "xxx"); b = serialization.serialize(map); assertNotNull(b); assertTrue(b.length > 0); Map m2 = serialization.deserialize(b, Map.class); assertEquals(map.size(), m2.size()); for (Map.Entry entry : map.entrySet()) { assertEquals(entry.getValue(), m2.get(entry.getKey())); } byte[] bytes = new byte[]{2, 34, 12, 24}; b = serialization.serialize(bytes); assertNotNull(b); assertTrue(b.length > 0); assertTrue(b[0] == 3); byte[] nbytes = serialization.deserialize(b, byte[].class); assertEquals(bytes.length, nbytes.length); for (int i = 0; i < nbytes.length; i++) { assertEquals(nbytes[i], bytes[i]); } }