/**
   * Invoked by the writer when it is leaving this node. Checks whether this node needs to be
   * emitted and takes of that if necessary.
   *
   * @param schema Schema context
   * @param writer Output writer
   * @return Parent node context
   * @throws IOException when writer reports it
   * @throws IllegalArgumentException if this node cannot be ended (e.g. root)
   */
  final JSONStreamWriterContext endNode(final SchemaContext schema, final JsonWriter writer)
      throws IOException {
    if (!emittedMyself && mandatory) {
      emitMyself(schema, writer);
    }

    if (emittedMyself) {
      emitEnd(writer);
    }
    return parent;
  }
 /**
  * Invoked whenever a child node is being emitted. Checks whether this node has been emitted, and
  * takes care of that if necessary. Also makes sure separator is emitted before a second and
  * subsequent child.
  *
  * @param schema Schema context
  * @param writer Output writer
  * @throws IOException when writer reports it
  */
 final void emittingChild(final SchemaContext schema, final JsonWriter writer) throws IOException {
   emitMyself(schema, writer);
 }