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 TypeMethodDescriptionvoid
Consumes the next token from the JSON stream and asserts that it is the beginning of a new array.void
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 underlyingReader
.void
endArray()
Consumes the next token from the JSON stream and asserts that it is the end of the current array.void
Consumes the next token from the JSON stream and asserts that it is the end of the current object.private void
getPath()
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 String
getPath
(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.boolean
hasNext()
Returns true if the current array or object has another element.private String
boolean
Returns theboolean
value of the next token, consuming it.double
Returns thedouble
value of the next token, consuming it.int
nextInt()
Returns theint
value of the next token, consuming it.(package private) JsonElement
long
nextLong()
Returns thelong
value of the next token, consuming it.nextName()
Returns the next token, aproperty name
, and consumes it.private String
nextName
(boolean skipName) void
nextNull()
Consumes the next token from the JSON stream and asserts that it is a literal null.Returns thestring
value of the next token, consuming it.peek()
Returns the type of the next token without consuming it.private Object
private Object
popStack()
void
private void
void
Skips 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:JsonReader
Consumes the next token from the JSON stream and asserts that it is the beginning of a new array.- Overrides:
beginArray
in classJsonReader
- Throws:
IOException
-
endArray
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 classJsonReader
- Throws:
IOException
-
beginObject
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 classJsonReader
- Throws:
IOException
-
endObject
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 classJsonReader
- Throws:
IOException
-
hasNext
Description copied from class:JsonReader
Returns true if the current array or object has another element.- Overrides:
hasNext
in classJsonReader
- Throws:
IOException
-
peek
Description copied from class:JsonReader
Returns the type of the next token without consuming it.- Overrides:
peek
in classJsonReader
- Throws:
IOException
-
peekStack
-
popStack
-
expect
- Throws:
IOException
-
nextName
- Throws:
IOException
-
nextName
Description copied from class:JsonReader
Returns the next token, aproperty name
, and consumes it.- Overrides:
nextName
in classJsonReader
- Throws:
IOException
- if the next token in the stream is not a property name.
-
nextString
Description copied from class:JsonReader
Returns thestring
value of the next token, consuming it. If the next token is a number, this method will return its string form.- Overrides:
nextString
in classJsonReader
- Throws:
IOException
-
nextBoolean
Description copied from class:JsonReader
Returns theboolean
value of the next token, consuming it.- Overrides:
nextBoolean
in classJsonReader
- Throws:
IOException
-
nextNull
Description copied from class:JsonReader
Consumes the next token from the JSON stream and asserts that it is a literal null.- Overrides:
nextNull
in classJsonReader
- Throws:
IOException
-
nextDouble
Description copied from class:JsonReader
Returns thedouble
value 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:
nextDouble
in classJsonReader
- Throws:
MalformedJsonException
- if the next literal value is NaN or Infinity and this reader is notlenient
.IOException
-
nextLong
Description copied from class:JsonReader
Returns thelong
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 Javalong
, this method throws.- Overrides:
nextLong
in classJsonReader
- Throws:
IOException
-
nextInt
Description copied from class:JsonReader
Returns theint
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 Javaint
, this method throws.- Overrides:
nextInt
in classJsonReader
- Throws:
IOException
-
nextJsonElement
- Throws:
IOException
-
close
Description copied from class:JsonReader
Closes this JSON reader and the underlyingReader
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classJsonReader
- Throws:
IOException
-
skipValue
Description copied from class:JsonReader
Skips 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:
skipValue
in classJsonReader
- Throws:
IOException
-
toString
- Overrides:
toString
in classJsonReader
-
promoteNameToValue
- Throws:
IOException
-
push
-
getPath
-
getPreviousPath
Description copied from class:JsonReader
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.
This method can be useful to add additional context to exception messages after a value has been consumed.
- Overrides:
getPreviousPath
in classJsonReader
- For JSON arrays the path points to the index of the previous element.
-
getPath
Description copied from class:JsonReader
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.
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:
getPath
in classJsonReader
-
locationString
-