StringAdapter extends TypeAdapter<String> { @Override public byte[] serialize(String value) { return Serialization.toByteArray(value); } StringAdapter(); @Override byte[] serialize(String value); @Override String deserialize(byte[] buffer, int bufferPosition); @Override int getSerializedSize(String value);  }
@Test public void testEncodeEmpty() { String string = ""; byte[] expected = {0, 0, 0, 0}; assertArrayEquals(expected, adapter.serialize(string)); }
@Test public void testEncode() { String string = "abcd"; byte[] expected = {0, 0, 0, 4, 'a', 'b', 'c', 'd'}; assertArrayEquals(expected, adapter.serialize(string)); }