Class JsonTreeWriter

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public final class JsonTreeWriter
    extends JsonWriter
    This writer creates a JsonElement.
    • Field Detail

      • UNWRITABLE_WRITER

        private static final java.io.Writer UNWRITABLE_WRITER
      • SENTINEL_CLOSED

        private static final JsonPrimitive SENTINEL_CLOSED
        Added to the top of the stack when this writer is closed to cause following ops to fail.
      • stack

        private final java.util.List<JsonElement> stack
        The JsonElements and JsonArrays under modification, outermost to innermost.
      • pendingName

        private java.lang.String pendingName
        The name for the next JSON object value. If non-null, the top of the stack is a JsonObject.
      • product

        private JsonElement product
        the JSON element constructed by this writer.
    • Constructor Detail

      • JsonTreeWriter

        public JsonTreeWriter()
    • Method Detail

      • get

        public JsonElement get()
        Returns the top level object produced by this writer.
      • beginArray

        public JsonWriter beginArray()
                              throws java.io.IOException
        Description copied from class: JsonWriter
        Begins encoding a new array. Each call to this method must be paired with a call to JsonWriter.endArray().
        Overrides:
        beginArray in class JsonWriter
        Returns:
        this writer.
        Throws:
        java.io.IOException
      • endArray

        public JsonWriter endArray()
                            throws java.io.IOException
        Description copied from class: JsonWriter
        Ends encoding the current array.
        Overrides:
        endArray in class JsonWriter
        Returns:
        this writer.
        Throws:
        java.io.IOException
      • beginObject

        public JsonWriter beginObject()
                               throws java.io.IOException
        Description copied from class: JsonWriter
        Begins encoding a new object. Each call to this method must be paired with a call to JsonWriter.endObject().
        Overrides:
        beginObject in class JsonWriter
        Returns:
        this writer.
        Throws:
        java.io.IOException
      • endObject

        public JsonWriter endObject()
                             throws java.io.IOException
        Description copied from class: JsonWriter
        Ends encoding the current object.
        Overrides:
        endObject in class JsonWriter
        Returns:
        this writer.
        Throws:
        java.io.IOException
      • name

        public JsonWriter name​(java.lang.String name)
                        throws java.io.IOException
        Description copied from class: JsonWriter
        Encodes the property name.
        Overrides:
        name in class JsonWriter
        Parameters:
        name - the name of the forthcoming value. May not be null.
        Returns:
        this writer.
        Throws:
        java.io.IOException
      • value

        public JsonWriter value​(java.lang.String value)
                         throws java.io.IOException
        Description copied from class: JsonWriter
        Encodes value.
        Overrides:
        value in class JsonWriter
        Parameters:
        value - the literal string value, or null to encode a null literal.
        Returns:
        this writer.
        Throws:
        java.io.IOException
      • jsonValue

        public JsonWriter jsonValue​(java.lang.String value)
                             throws java.io.IOException
        Description copied from class: JsonWriter
        Writes value directly to the writer without quoting or escaping. This might not be supported by all implementations, if not supported an UnsupportedOperationException is thrown.
        Overrides:
        jsonValue in class JsonWriter
        Parameters:
        value - the literal string value, or null to encode a null literal.
        Returns:
        this writer.
        Throws:
        java.io.IOException
      • nullValue

        public JsonWriter nullValue()
                             throws java.io.IOException
        Description copied from class: JsonWriter
        Encodes null.
        Overrides:
        nullValue in class JsonWriter
        Returns:
        this writer.
        Throws:
        java.io.IOException
      • value

        public JsonWriter value​(boolean value)
                         throws java.io.IOException
        Description copied from class: JsonWriter
        Encodes value.
        Overrides:
        value in class JsonWriter
        Returns:
        this writer.
        Throws:
        java.io.IOException
      • value

        public JsonWriter value​(java.lang.Boolean value)
                         throws java.io.IOException
        Description copied from class: JsonWriter
        Encodes value.
        Overrides:
        value in class JsonWriter
        Returns:
        this writer.
        Throws:
        java.io.IOException
      • value

        public JsonWriter value​(float value)
                         throws java.io.IOException
        Description copied from class: JsonWriter
        Encodes value.
        Overrides:
        value in class JsonWriter
        Parameters:
        value - a finite value, or if lenient, also NaN or infinity.
        Returns:
        this writer.
        Throws:
        java.io.IOException
      • value

        public JsonWriter value​(double value)
                         throws java.io.IOException
        Description copied from class: JsonWriter
        Encodes value.
        Overrides:
        value in class JsonWriter
        Parameters:
        value - a finite value, or if lenient, also NaN or infinity.
        Returns:
        this writer.
        Throws:
        java.io.IOException
      • value

        public JsonWriter value​(long value)
                         throws java.io.IOException
        Description copied from class: JsonWriter
        Encodes value.
        Overrides:
        value in class JsonWriter
        Returns:
        this writer.
        Throws:
        java.io.IOException
      • value

        public JsonWriter value​(java.lang.Number value)
                         throws java.io.IOException
        Description copied from class: JsonWriter
        Encodes value. The value is written by directly writing the Object.toString() result to JSON. Implementations must make sure that the result represents a valid JSON number.
        Overrides:
        value in class JsonWriter
        Parameters:
        value - a finite value, or if lenient, also NaN or infinity.
        Returns:
        this writer.
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        Description copied from class: JsonWriter
        Ensures all buffered data is written to the underlying Writer and flushes that writer.
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class JsonWriter
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Description copied from class: JsonWriter
        Flushes and closes this writer and the underlying Writer.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class JsonWriter
        Throws:
        java.io.IOException - if the JSON document is incomplete.