Class JsonTreeReader

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

    public final class JsonTreeReader
    extends JsonReader
    This reader walks the elements of a JsonElement as if it was coming from a character stream.
    Author:
    Jesse Wilson
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void beginArray()
      Consumes the next token from the JSON stream and asserts that it is the beginning of a new array.
      void beginObject()
      Consumes the next token from the JSON stream and asserts that it is the beginning of a new object.
      void close()
      Closes this JSON reader and the underlying Reader.
      void endArray()
      Consumes the next token from the JSON stream and asserts that it is the end of the current array.
      void endObject()
      Consumes the next token from the JSON stream and asserts that it is the end of the current object.
      java.lang.String getPath()
      Returns a JsonPath to the current location in the JSON value.
      boolean hasNext()
      Returns true if the current array or object has another element.
      boolean nextBoolean()
      Returns the boolean value of the next token, consuming it.
      double nextDouble()
      Returns the double value of the next token, consuming it.
      int nextInt()
      Returns the int value of the next token, consuming it.
      long nextLong()
      Returns the long value of the next token, consuming it.
      java.lang.String nextName()
      Returns the next token, a property name, and consumes it.
      void nextNull()
      Consumes the next token from the JSON stream and asserts that it is a literal null.
      java.lang.String nextString()
      Returns the string value of the next token, consuming it.
      JsonToken peek()
      Returns the type of the next token without consuming it.
      void promoteNameToValue()  
      void skipValue()
      Skips the next value recursively.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • JsonTreeReader

        public JsonTreeReader​(JsonElement element)
    • Method Detail

      • beginArray

        public void beginArray()
                        throws java.io.IOException
        Description copied from class: JsonReader
        Consumes the next token from the JSON stream and asserts that it is the beginning of a new array.
        Overrides:
        beginArray in class JsonReader
        Throws:
        java.io.IOException
      • endArray

        public void endArray()
                      throws java.io.IOException
        Description copied from class: JsonReader
        Consumes the next token from the JSON stream and asserts that it is the end of the current array.
        Overrides:
        endArray in class JsonReader
        Throws:
        java.io.IOException
      • beginObject

        public void beginObject()
                         throws java.io.IOException
        Description copied from class: JsonReader
        Consumes the next token from the JSON stream and asserts that it is the beginning of a new object.
        Overrides:
        beginObject in class JsonReader
        Throws:
        java.io.IOException
      • endObject

        public void endObject()
                       throws java.io.IOException
        Description copied from class: JsonReader
        Consumes the next token from the JSON stream and asserts that it is the end of the current object.
        Overrides:
        endObject in class JsonReader
        Throws:
        java.io.IOException
      • hasNext

        public boolean hasNext()
                        throws java.io.IOException
        Description copied from class: JsonReader
        Returns true if the current array or object has another element.
        Overrides:
        hasNext in class JsonReader
        Throws:
        java.io.IOException
      • peek

        public JsonToken peek()
                       throws java.io.IOException
        Description copied from class: JsonReader
        Returns the type of the next token without consuming it.
        Overrides:
        peek in class JsonReader
        Throws:
        java.io.IOException
      • nextName

        public java.lang.String nextName()
                                  throws java.io.IOException
        Description copied from class: JsonReader
        Returns the next token, a property name, and consumes it.
        Overrides:
        nextName in class JsonReader
        Throws:
        java.io.IOException - if the next token in the stream is not a property name.
      • nextString

        public java.lang.String nextString()
                                    throws java.io.IOException
        Description copied from class: JsonReader
        Returns the string value of the next token, consuming it. If the next token is a number, this method will return its string form.
        Overrides:
        nextString in class JsonReader
        Throws:
        java.io.IOException
      • nextBoolean

        public boolean nextBoolean()
                            throws java.io.IOException
        Description copied from class: JsonReader
        Returns the boolean value of the next token, consuming it.
        Overrides:
        nextBoolean in class JsonReader
        Throws:
        java.io.IOException
      • nextNull

        public void nextNull()
                      throws java.io.IOException
        Description copied from class: JsonReader
        Consumes the next token from the JSON stream and asserts that it is a literal null.
        Overrides:
        nextNull in class JsonReader
        Throws:
        java.io.IOException
      • nextDouble

        public double nextDouble()
                          throws java.io.IOException
        Description copied from class: JsonReader
        Returns the double value of the next token, consuming it. If the next token is a string, this method will attempt to parse it as a double using Double.parseDouble(String).
        Overrides:
        nextDouble in class JsonReader
        Throws:
        java.io.IOException
      • nextLong

        public long nextLong()
                      throws java.io.IOException
        Description copied from class: JsonReader
        Returns the long value of the next token, consuming it. If the next token is a string, this method will attempt to parse it as a long. If the next token's numeric value cannot be exactly represented by a Java long, this method throws.
        Overrides:
        nextLong in class JsonReader
        Throws:
        java.io.IOException
      • nextInt

        public int nextInt()
                    throws java.io.IOException
        Description copied from class: JsonReader
        Returns the int value of the next token, consuming it. If the next token is a string, this method will attempt to parse it as an int. If the next token's numeric value cannot be exactly represented by a Java int, this method throws.
        Overrides:
        nextInt in class JsonReader
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Description copied from class: JsonReader
        Closes this JSON reader and the underlying Reader.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class JsonReader
        Throws:
        java.io.IOException
      • skipValue

        public void skipValue()
                       throws java.io.IOException
        Description copied from class: JsonReader
        Skips the next value recursively. If it is an object or array, all nested elements are skipped. This method is intended for use when the JSON token stream contains unrecognized or unhandled values.
        Overrides:
        skipValue in class JsonReader
        Throws:
        java.io.IOException
      • promoteNameToValue

        public void promoteNameToValue()
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • getPath

        public java.lang.String getPath()
        Description copied from class: JsonReader
        Returns a JsonPath to the current location in the JSON value.
        Overrides:
        getPath in class JsonReader