public static <T> byte[] toBytes(final T object,
                                   final @NotNull DataExternalizer<? super T> externalizer) throws IOException {
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try (final DataOutputStream dos = new DataOutputStream(bos)) {
      externalizer.save(dos, object);
    }
    return bos.toByteArray();
  }
public static <T> byte[] toBytes(final T object,
                                   final @NotNull DataExternalizer<? super T> externalizer)