BooleanArrayAdapter extends TypeAdapter<boolean[]> { @Override public byte[] serialize(boolean[] array) { final byte[] buf = new byte[getSerializedSize(array)]; if (array.length == 0) { return buf; } int pos = 0; Serialization.put(buf, Serialization.toByteArray(array.length), pos); pos += Serialization.SIZE_OF_INT; for (boolean val : array) { byte[] arr = Serialization.toByteArray(val); Serialization.put(buf, arr, pos); pos += Serialization.SIZE_OF_BOOL; } return buf; } BooleanArrayAdapter(); @Override byte[] serialize(boolean[] array); @Override boolean[] deserialize(byte[] array, int pos); @Override int getSerializedSize(boolean[] value);  }
@Test public void testEncodeEmptyArray() { final boolean[] array = {}; final byte[] serialized = adapter.serialize(array); assertArrayEquals(new byte[4], serialized); }
@Test public void testEncode() { final boolean[] array = {true, false, true, false}; final byte[] expected = { 0, 0, 0, 4, 1, 0, 1, 0 }; final byte[] serialized = adapter.serialize(array); assertArrayEquals(expected, serialized); }