StringArrayAdapter extends TypeAdapter<String[]> { @Override public String[] deserialize(byte[] array, int pos) { int cursor = pos; int length = Serialization.readInt(array, cursor); cursor += Serialization.SIZE_OF_INT; String[] stringArray = new String[length]; for (int i = 0; i < length; i++) { String string = Serialization.readString(array, cursor); stringArray[i] = string; cursor += Serialization.SIZE_OF_INT + Serialization.readInt(array, cursor); } return stringArray; } StringArrayAdapter(); @Override byte[] serialize(String[] data); @Override String[] deserialize(byte[] array, int pos); @Override int getSerializedSize(String[] value);  }
@Test public void testDecode() { byte[] buffer = {0, 0, 0, 2, 0, 0, 0, 3, 'f', 'o', 'o', 0, 0, 0, 3, 'b', 'a', 'r'}; String[] expected = {"foo", "bar"}; assertArrayEquals(expected, adapter.deserialize(buffer, 0)); }
@Test public void testDecodeEmpty() { byte[] buffer = {0, 0, 0, 0}; String[] expected = {}; assertArrayEquals(expected, adapter.deserialize(buffer, 0)); }