- java.lang.Object
-
- com.google.gson.stream.JsonReader
-
- com.google.gson.internal.bind.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.
-
-
Field Summary
Fields Modifier and Type Field Description private int[]pathIndicesprivate java.lang.String[]pathNamesprivate static java.lang.ObjectSENTINEL_CLOSEDprivate java.lang.Object[]stackprivate intstackSizeprivate static java.io.ReaderUNREADABLE_READER
-
Constructor Summary
Constructors Constructor Description JsonTreeReader(JsonElement element)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginArray()Consumes the next token from the JSON stream and asserts that it is the beginning of a new array.voidbeginObject()Consumes 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.voidendObject()Consumes the next token from the JSON stream and asserts that it is the end of the current object.private voidexpect(JsonToken expected)java.lang.StringgetPath()Returns a JsonPath to the current location in the JSON value.booleanhasNext()Returns true if the current array or object has another element.private java.lang.StringlocationString()booleannextBoolean()Returns thebooleanvalue of the next token, consuming it.doublenextDouble()Returns thedoublevalue of the next token, consuming it.intnextInt()Returns theintvalue of the next token, consuming it.longnextLong()Returns thelongvalue of the next token, consuming it.java.lang.StringnextName()Returns the next token, aproperty name, and consumes it.voidnextNull()Consumes the next token from the JSON stream and asserts that it is a literal null.java.lang.StringnextString()Returns thestringvalue of the next token, consuming it.JsonTokenpeek()Returns the type of the next token without consuming it.private java.lang.ObjectpeekStack()private java.lang.ObjectpopStack()voidpromoteNameToValue()private voidpush(java.lang.Object newTop)voidskipValue()Skips the next value recursively.java.lang.StringtoString()-
Methods inherited from class com.google.gson.stream.JsonReader
isLenient, setLenient
-
-
-
-
Field Detail
-
UNREADABLE_READER
private static final java.io.Reader UNREADABLE_READER
-
SENTINEL_CLOSED
private static final java.lang.Object SENTINEL_CLOSED
-
stack
private java.lang.Object[] stack
-
stackSize
private int stackSize
-
pathNames
private java.lang.String[] pathNames
-
pathIndices
private int[] pathIndices
-
-
Constructor Detail
-
JsonTreeReader
public JsonTreeReader(JsonElement element)
-
-
Method Detail
-
beginArray
public void beginArray() throws java.io.IOExceptionDescription 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:
java.io.IOException
-
endArray
public void endArray() throws java.io.IOExceptionDescription 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:
java.io.IOException
-
beginObject
public void beginObject() throws java.io.IOExceptionDescription 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:
java.io.IOException
-
endObject
public void endObject() throws java.io.IOExceptionDescription 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:
java.io.IOException
-
hasNext
public boolean hasNext() throws java.io.IOExceptionDescription copied from class:JsonReaderReturns true if the current array or object has another element.- Overrides:
hasNextin classJsonReader- Throws:
java.io.IOException
-
peek
public JsonToken peek() throws java.io.IOException
Description copied from class:JsonReaderReturns the type of the next token without consuming it.- Overrides:
peekin classJsonReader- Throws:
java.io.IOException
-
peekStack
private java.lang.Object peekStack()
-
popStack
private java.lang.Object popStack()
-
expect
private void expect(JsonToken expected) throws java.io.IOException
- Throws:
java.io.IOException
-
nextName
public java.lang.String nextName() throws java.io.IOExceptionDescription copied from class:JsonReaderReturns the next token, aproperty name, and consumes it.- Overrides:
nextNamein classJsonReader- 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.IOExceptionDescription 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:
java.io.IOException
-
nextBoolean
public boolean nextBoolean() throws java.io.IOExceptionDescription copied from class:JsonReaderReturns thebooleanvalue of the next token, consuming it.- Overrides:
nextBooleanin classJsonReader- Throws:
java.io.IOException
-
nextNull
public void nextNull() throws java.io.IOExceptionDescription copied from class:JsonReaderConsumes the next token from the JSON stream and asserts that it is a literal null.- Overrides:
nextNullin classJsonReader- Throws:
java.io.IOException
-
nextDouble
public double nextDouble() throws java.io.IOExceptionDescription 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:
java.io.IOException
-
nextLong
public long nextLong() throws java.io.IOExceptionDescription 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:
java.io.IOException
-
nextInt
public int nextInt() throws java.io.IOExceptionDescription 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:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionDescription copied from class:JsonReaderCloses this JSON reader and the underlyingReader.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classJsonReader- Throws:
java.io.IOException
-
skipValue
public void skipValue() throws java.io.IOExceptionDescription copied from class:JsonReaderSkips 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:
skipValuein classJsonReader- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classJsonReader
-
promoteNameToValue
public void promoteNameToValue() throws java.io.IOException- Throws:
java.io.IOException
-
push
private void push(java.lang.Object newTop)
-
getPath
public java.lang.String getPath()
Description copied from class:JsonReaderReturns a JsonPath to the current location in the JSON value.- Overrides:
getPathin classJsonReader
-
locationString
private java.lang.String locationString()
-
-