Class Json5Writer


  • public final class Json5Writer
    extends java.lang.Object
    Writes a tree of Json5Element's into their string literal representation by using a write stream.
    • Constructor Detail

      • Json5Writer

        public Json5Writer​(Json5Options options,
                           java.io.Writer writer)
        Creates a new instance that writes a JSON5-encoded stream to writer.

        Note: The writer must be closed after operation (Writer.close())!

        Parameters:
        options - Parsing and serialization options
        writer - Output stream. For the best performance, use a BufferedWriter.
    • Method Detail

      • write

        public void write​(Json5Element element)
                   throws java.io.IOException
        Encodes and writes the provided Json5Element into json5 according to the specification and the configured options. The element can be any json5 element. All child trees will be included. This function writes with depth 0 and expects a root element. For nested elements, see the other write methods.
        Parameters:
        element - Element to encode
        Throws:
        java.io.IOException - If an I/O error occurs
        See Also:
        Configuration options, write(Json5Element, int)
      • write

        public void write​(Json5Element element,
                          int depth)
                   throws java.io.IOException
        Encodes and writes the provided Json5Element into json5 according to the specification and the configured options. The element can be any json5 element. All child trees will be included.
        Parameters:
        element - Element to encode
        depth - Depth of the current Json5 tree. Root node is 0. Counts +1 on every child element.
        Throws:
        java.io.IOException - If an I/O error occurs
        See Also:
        Configuration options, write(Json5Element)
      • writeComment

        public void writeComment​(Json5Element element,
                                 int depth)
                          throws java.io.IOException
        Writes any associated comments for the provided Json5Element. Checks if Json5Options.isWriteComments() is true and if the element has any comment assigned.
        Parameters:
        element - Element target
        depth - Depth to use for writing
        Throws:
        java.io.IOException - If an I/O error occurs
      • writeNull

        public void writeNull()
                       throws java.io.IOException
        Writes the equivalent of a Json5Null(null) value.
        Throws:
        java.io.IOException - If an I/O error occurs.
      • writePrimitive

        public void writePrimitive​(Json5Primitive primitive)
                            throws java.io.IOException
        Writes the provided primitive to the stream and encodes it if necessary.
        Parameters:
        primitive - Primitive value.
        Throws:
        java.io.IOException - If an I/O error occurs.
      • writeObject

        public void writeObject​(Json5Object object,
                                int depth)
                         throws java.io.IOException
        Writes the provided Json5Object to the stream.
        Parameters:
        object - Object to encode
        depth - Depth to use for writing
        Throws:
        java.io.IOException - If an I/O error occurs.
        See Also:
        write(Json5Element)
      • writeArray

        public void writeArray​(Json5Array array,
                               int depth)
                        throws java.io.IOException
        Writes the provided Json5Array to the stream.
        Parameters:
        array - Array to encode
        depth - Depth to use for writing
        Throws:
        java.io.IOException - If an I/O error occurs.
        See Also:
        write(Json5Element)
      • formatNumberString

        public java.lang.String formatNumberString​(java.lang.String numberString,
                                                   int numberRadix)
      • quoteKey

        public java.lang.String quoteKey​(java.lang.String key)
      • quote

        public java.lang.String quote​(java.lang.String string)