code: public static void serialize(Object value, OutputStream outputStream) throws IOException {
      try {
        new ObjectOutputStream(outputStream).writeObject(value);
      } finally {
        outputStream.close();
      }
    }
docs: Serializes the given object value to an output stream, and close the output stream.
  
  @param value object value to serialize
  @param outputStream output stream to serialize into
  @since 1.16