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
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
-
-
Constructor Summary
Constructors Constructor Description JsonTreeReader(JsonElement element)
-
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 underlyingReader
.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.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 theboolean
value of the next token, consuming it.double
nextDouble()
Returns thedouble
value of the next token, consuming it.int
nextInt()
Returns theint
value of the next token, consuming it.long
nextLong()
Returns thelong
value of the next token, consuming it.String
nextName()
Returns the next token, aproperty name
, and consumes it.void
nextNull()
Consumes the next token from the JSON stream and asserts that it is a literal null.String
nextString()
Returns thestring
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.String
toString()
-
Methods inherited from class com.google.gson.stream.JsonReader
isLenient, setLenient
-
-
-
-
Constructor Detail
-
JsonTreeReader
public JsonTreeReader(JsonElement element)
-
-
Method Detail
-
beginArray
public void beginArray() throws 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 classJsonReader
- Throws:
IOException
-
endArray
public void endArray() throws 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 classJsonReader
- Throws:
IOException
-
beginObject
public void beginObject() throws 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 classJsonReader
- Throws:
IOException
-
endObject
public void endObject() throws 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 classJsonReader
- Throws:
IOException
-
hasNext
public boolean hasNext() throws IOException
Description copied from class:JsonReader
Returns true if the current array or object has another element.- Overrides:
hasNext
in classJsonReader
- Throws:
IOException
-
peek
public JsonToken peek() throws IOException
Description copied from class:JsonReader
Returns the type of the next token without consuming it.- Overrides:
peek
in classJsonReader
- Throws:
IOException
-
nextName
public String nextName() throws IOException
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
public String nextString() throws IOException
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
public boolean nextBoolean() throws IOException
Description copied from class:JsonReader
Returns theboolean
value of the next token, consuming it.- Overrides:
nextBoolean
in classJsonReader
- Throws:
IOException
-
nextNull
public void nextNull() throws 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 classJsonReader
- Throws:
IOException
-
nextDouble
public double nextDouble() throws IOException
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:
IOException
-
nextLong
public long nextLong() throws IOException
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
public int nextInt() throws IOException
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
-
close
public void close() throws IOException
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
public void skipValue() throws 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 classJsonReader
- Throws:
IOException
-
toString
public String toString()
- Overrides:
toString
in classJsonReader
-
promoteNameToValue
public void promoteNameToValue() throws IOException
- Throws:
IOException
-
getPath
public String getPath()
Description copied from class:JsonReader
Returns a JsonPath to the current location in the JSON value.- Overrides:
getPath
in classJsonReader
-
-