Interface NodeWriter

  • All Superinterfaces:
    AutoCloseable, Closeable

    public interface NodeWriter
    extends Closeable
    A writer that builds a node tree that is later serialized as JSON or XML format. An writer instance is created using a dedicated Factory.

    Client needs to make sure the close() method is always called, so that the serialization can complete and temporary resources can be disposed.

    This interface is not intended to be implemented by clients.

    Since:
    2.0
    See Also:
    NodeContentProducer, NodeWriter.Factory.XML, NodeWriter.Factory.JSON
    • Method Detail

      • startDocument

        NodeWriter startDocument​(String name)
                          throws IOException
        Start the production of the node tree.
        Parameters:
        name - the name of the root node. This name is not used by the JSON implementation.
        Returns:
        the same node writer instance.
        Throws:
        IOException - if anything prevents the writing process.
      • endDocument

        NodeWriter endDocument()
                        throws IOException
        Finalizes the production of the node tree.
        Returns:
        the same node writer instance.
        Throws:
        IOException - if anything prevents the writing process.
      • startNode

        NodeWriter startNode()
                      throws IOException
        Starts a new node production, child of the current node which is expected to be an array node. The new node name will be the one of the parent array node.
        Returns:
        the same node writer instance.
        Throws:
        IOException - if anything prevents the writing process.
        See Also:
        startArray(String)
      • startNode

        NodeWriter startNode​(String name)
                      throws IOException
        Starts a new node production with the specified name.
        Parameters:
        name - the node name.
        Returns:
        the same node writer instance.
        Throws:
        IOException - if anything prevents the writing process.
      • endNode

        NodeWriter endNode()
                    throws IOException
        Ends the current node production.
        Returns:
        the same node writer instance.
        Throws:
        IOException - if anything prevents the writing process.
      • startArray

        NodeWriter startArray​(String name)
                       throws IOException
        Starts a new array node production. Client is expected to call startNode() method for each item of the array.
        Parameters:
        name - the node name.
        Returns:
        the same node writer instance.
        Throws:
        IOException - if anything prevents the writing process.
        See Also:
        startNode()
      • endArray

        NodeWriter endArray()
                     throws IOException
        Ends the current array node production.
        Returns:
        the same node writer instance.
        Throws:
        IOException - if anything prevents the writing process.
      • write

        NodeWriter write​(String name,
                         String value)
                  throws IOException
        Writes a name/value pair on the current node.
        Parameters:
        name - the attribute name.
        value - the attribute value.
        Returns:
        the same node writer instance.
        Throws:
        IOException - if anything prevents the writing process.