Package com.google.gson.internal.bind
Class JsonTreeReader
java.lang.Object
com.google.gson.stream.JsonReader
com.google.gson.internal.bind.JsonTreeReader
- All Implemented Interfaces:
Closeable,AutoCloseable
This reader walks the elements of a JsonElement as if it was coming from a
character stream.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidConsumes the next token from the JSON stream and asserts that it is the beginning of a new array.voidConsumes the next token from the JSON stream and asserts that it is the beginning of a new object.voidclose()Closes this JSON reader and the underlyingReader.voidendArray()Consumes the next token from the JSON stream and asserts that it is the end of the current array.voidConsumes the next token from the JSON stream and asserts that it is the end of the current object.private voidgetPath()Returns a JSONPath in dot-notation to the next (or current) location in the JSON document: For JSON arrays the path points to the index of the next element (even if there are no further elements). For JSON objects the path points to the last property, or to the current property if its name has already been consumed.private StringgetPath(boolean usePreviousPath) Returns a JSONPath in dot-notation to the previous (or current) location in the JSON document: For JSON arrays the path points to the index of the previous element.
If no element has been consumed yet it uses the index 0 (even if there are no elements). For JSON objects the path points to the last property, or to the current property if its name has already been consumed.booleanhasNext()Returns true if the current array or object has another element.private StringbooleanReturns thebooleanvalue of the next token, consuming it.doubleReturns thedoublevalue of the next token, consuming it.intnextInt()Returns theintvalue of the next token, consuming it.(package private) JsonElementlongnextLong()Returns thelongvalue of the next token, consuming it.nextName()Returns the next token, aproperty name, and consumes it.private StringnextName(boolean skipName) voidnextNull()Consumes the next token from the JSON stream and asserts that it is a literal null.Returns thestringvalue of the next token, consuming it.peek()Returns the type of the next token without consuming it.private Objectprivate ObjectpopStack()voidprivate voidvoidSkips the next value recursively.toString()Methods inherited from class com.google.gson.stream.JsonReader
isLenient, setLenient
-
Field Details
-
UNREADABLE_READER
-
SENTINEL_CLOSED
-
stack
-
stackSize
private int stackSize -
pathNames
-
pathIndices
private int[] pathIndices
-
-
Constructor Details
-
JsonTreeReader
-
-
Method Details
-
beginArray
Description copied from class:JsonReaderConsumes the next token from the JSON stream and asserts that it is the beginning of a new array.- Overrides:
beginArrayin classJsonReader- Throws:
IOException
-
endArray
Description copied from class:JsonReaderConsumes the next token from the JSON stream and asserts that it is the end of the current array.- Overrides:
endArrayin classJsonReader- Throws:
IOException
-
beginObject
Description copied from class:JsonReaderConsumes the next token from the JSON stream and asserts that it is the beginning of a new object.- Overrides:
beginObjectin classJsonReader- Throws:
IOException
-
endObject
Description copied from class:JsonReaderConsumes the next token from the JSON stream and asserts that it is the end of the current object.- Overrides:
endObjectin classJsonReader- Throws:
IOException
-
hasNext
Description copied from class:JsonReaderReturns true if the current array or object has another element.- Overrides:
hasNextin classJsonReader- Throws:
IOException
-
peek
Description copied from class:JsonReaderReturns the type of the next token without consuming it.- Overrides:
peekin classJsonReader- Throws:
IOException
-
peekStack
-
popStack
-
expect
- Throws:
IOException
-
nextName
- Throws:
IOException
-
nextName
Description copied from class:JsonReaderReturns the next token, aproperty name, and consumes it.- Overrides:
nextNamein classJsonReader- Throws:
IOException- if the next token in the stream is not a property name.
-
nextString
Description copied from class:JsonReaderReturns thestringvalue of the next token, consuming it. If the next token is a number, this method will return its string form.- Overrides:
nextStringin classJsonReader- Throws:
IOException
-
nextBoolean
Description copied from class:JsonReaderReturns thebooleanvalue of the next token, consuming it.- Overrides:
nextBooleanin classJsonReader- Throws:
IOException
-
nextNull
Description copied from class:JsonReaderConsumes the next token from the JSON stream and asserts that it is a literal null.- Overrides:
nextNullin classJsonReader- Throws:
IOException
-
nextDouble
Description copied from class:JsonReaderReturns thedoublevalue of the next token, consuming it. If the next token is a string, this method will attempt to parse it as a double usingDouble.parseDouble(String).- Overrides:
nextDoublein classJsonReader- Throws:
IOException
-
nextLong
Description copied from class:JsonReaderReturns thelongvalue 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 Javalong, this method throws.- Overrides:
nextLongin classJsonReader- Throws:
IOException
-
nextInt
Description copied from class:JsonReaderReturns theintvalue 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 Javaint, this method throws.- Overrides:
nextIntin classJsonReader- Throws:
IOException
-
nextJsonElement
- Throws:
IOException
-
close
Description copied from class:JsonReaderCloses this JSON reader and the underlyingReader.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classJsonReader- Throws:
IOException
-
skipValue
Description copied from class:JsonReaderSkips the next value recursively. This method is intended for use when the JSON token stream contains unrecognized or unhandled values.The behavior depends on the type of the next JSON token:
- Start of a JSON array or object: It and all of its nested values are skipped.
- Primitive value (for example a JSON number): The primitive value is skipped.
- Property name: Only the name but not the value of the property is skipped.
skipValue()has to be called again to skip the property value as well. - End of a JSON array or object: Only this end token is skipped.
- End of JSON document: Skipping has no effect, the next token continues to be the end of the document.
- Overrides:
skipValuein classJsonReader- Throws:
IOException
-
toString
- Overrides:
toStringin classJsonReader
-
promoteNameToValue
- Throws:
IOException
-
push
-
getPath
-
getPreviousPath
Description copied from class:JsonReaderReturns a JSONPath in dot-notation to the previous (or current) location in the JSON document:- For JSON arrays the path points to the index of the previous element.
If no element has been consumed yet it uses the index 0 (even if there are no elements). - For JSON objects the path points to the last property, or to the current property if its name has already been consumed.
This method can be useful to add additional context to exception messages after a value has been consumed.
- Overrides:
getPreviousPathin classJsonReader
- For JSON arrays the path points to the index of the previous element.
-
getPath
Description copied from class:JsonReaderReturns a JSONPath in dot-notation to the next (or current) location in the JSON document:- For JSON arrays the path points to the index of the next element (even if there are no further elements).
- For JSON objects the path points to the last property, or to the current property if its name has already been consumed.
This method can be useful to add additional context to exception messages before a value is consumed, for example when the peeked token is unexpected.
- Overrides:
getPathin classJsonReader
-
locationString
-