/**
   * Writes the given object within the current marshal context.
   *
   * <p>This method is unlike {@link #writeObject(Object, Key)}, which creates a new child marshal
   * context. This method instead uses the current context to marshal the object, using the {@link
   * Marshaler} instance specified at construction time.
   *
   * @param object object to be written
   * @throws MarshalingException if marshaling the given object fails (for instance, when a
   *     user-defined {@link Marshaler#put(Object, MarshalContext)} implementation throws or causes
   *     a {@link MarshalingException})
   * @throws IOException if the operation failed because of an I/O error
   */
  public void acceptObject(Object object) throws IOException {
    startIfNeeded();

    ObjectAction action = ObjectAction.MARSHAL;
    if (isSelfContained(marshaler, object)) {
      action = Objects.requireNonNull(marshalTarget.putImmutableObject(object));
    }
    if (action == ObjectAction.MARSHAL) {
      uncheckedPut(marshaler, object);
    }
  }