NumberArrayAdapter extends TypeAdapter<double[]> { @Override public byte[] serialize(double[] 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 (double val : array) { byte[] arr = Serialization.toByteArray(val); Serialization.put(buf, arr, pos); pos += Serialization.SIZE_OF_DOUBLE; } return buf; } NumberArrayAdapter(); @Override byte[] serialize(double[] array); @Override double[] deserialize(byte[] buffer, int bufferPosition); @Override int getSerializedSize(double[] value);  }
@Test public void testEncodeEmpty() { double[] array = {}; byte[] expected = {0, 0, 0, 0}; assertArrayEquals(expected, adapter.serialize(array)); }