Top Description Fields Constructors Methods
com.google.gson.internal.bind

public final Class JsonTreeReader

extends JsonReader
Class Inheritance
Imports
com.google.errorprone.annotations.CanIgnoreReturnValue, com.google.gson.JsonArray, .JsonElement, .JsonNull, .JsonObject, .JsonPrimitive, com.google.gson.stream.JsonReader, .JsonToken, .MalformedJsonException, java.io.IOException, .Reader, java.util.Arrays, .Iterator, .Map

This reader walks the elements of a JsonElement as if it was coming from a character stream.
Author
Jesse Wilson

Field Summary

Modifier and TypeField and Description
private int[]
private String[]
private static final Object
private Object[]
private int
stackSize

Hides com.google.gson.stream.JsonReader.stackSize.

The used size of stack; the value at stackSize - 1 is the value last placed on the stack.
private static final Reader

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
beginArray()

Overrides com.google.gson.stream.JsonReader.beginArray.

Consumes the next token from the JSON stream and asserts that it is the beginning of a new array.

public void
beginObject()

Overrides com.google.gson.stream.JsonReader.beginObject.

Consumes the next token from the JSON stream and asserts that it is the beginning of a new object.

public void
close()

Overrides com.google.gson.stream.JsonReader.close.

Implements java.io.Closeable.close.

Closes this JSON reader and the underlying Reader.

public void
endArray()

Overrides com.google.gson.stream.JsonReader.endArray.

Consumes the next token from the JSON stream and asserts that it is the end of the current array.

public void
endObject()

Overrides com.google.gson.stream.JsonReader.endObject.

Consumes the next token from the JSON stream and asserts that it is the end of the current object.

private void
expect(JsonToken expected)

private String
getPath(boolean usePreviousPath)

Hides com.google.gson.stream.JsonReader.getPath.

public String
getPath()

Overrides com.google.gson.stream.JsonReader.getPath.

Returns a JSONPath in dot-notation to the next (or current) location in the JSON document.

public String
getPreviousPath()

Overrides com.google.gson.stream.JsonReader.getPreviousPath.

Returns a JSONPath in dot-notation to the previous (or current) location in the JSON document.

public boolean
hasNext()

Overrides com.google.gson.stream.JsonReader.hasNext.

Returns true if the current array or object has another element.

private String
public boolean
nextBoolean()

Overrides com.google.gson.stream.JsonReader.nextBoolean.

Returns the boolean value of the next token, consuming it.

public double
nextDouble()

Overrides com.google.gson.stream.JsonReader.nextDouble.

Returns the double value of the next token, consuming it.

public int
nextInt()

Overrides com.google.gson.stream.JsonReader.nextInt.

Returns the int value of the next token, consuming it.

pack-priv JsonElement
public long
nextLong()

Overrides com.google.gson.stream.JsonReader.nextLong.

Returns the long value of the next token, consuming it.

private String
nextName(boolean skipName)

public String
nextName()

Overrides com.google.gson.stream.JsonReader.nextName.

Returns the next token, a property name, and consumes it.

public void
nextNull()

Overrides com.google.gson.stream.JsonReader.nextNull.

Consumes the next token from the JSON stream and asserts that it is a literal null.

public String
nextString()

Overrides com.google.gson.stream.JsonReader.nextString.

Returns the string value of the next token, consuming it.

public JsonToken
peek()

Overrides com.google.gson.stream.JsonReader.peek.

Returns the type of the next token without consuming it.

private Object
private Object
public void
private void
push(Object newTop)

public void
skipValue()

Overrides com.google.gson.stream.JsonReader.skipValue.

Skips the next value recursively.

public String
toString()

Overrides com.google.gson.stream.JsonReader.toString.

Returns a string representation of the object.

Inherited from com.google.gson.stream.JsonReader:
getNestingLimitgetStrictnessisLenientsetLenientsetNestingLimitsetStrictness

Field Detail

pathIndicesback to summary
private int[] pathIndices

Hides com.google.gson.stream.JsonReader.pathIndices.

pathNamesback to summary
private String[] pathNames

Hides com.google.gson.stream.JsonReader.pathNames.

SENTINEL_CLOSEDback to summary
private static final Object SENTINEL_CLOSED
stackback to summary
private Object[] stack

Hides com.google.gson.stream.JsonReader.stack.

The nesting stack. Using a manual array rather than an ArrayList saves 20%.

stackSizeback to summary
private int stackSize

Hides com.google.gson.stream.JsonReader.stackSize.

The used size of stack; the value at stackSize - 1 is the value last placed on the stack. stackSize might differ from the nesting depth, because the stack also contains temporary additional objects, for example for a JsonArray it contains the JsonArray object as well as the corresponding iterator.

UNREADABLE_READERback to summary
private static final Reader UNREADABLE_READER

Constructor Detail

JsonTreeReaderback to summary
public JsonTreeReader(JsonElement element)

Method Detail

beginArrayback to summary
public void beginArray() throws IOException

Overrides com.google.gson.stream.JsonReader.beginArray.

Doc from com.google.gson.stream.JsonReader.beginArray.

Consumes the next token from the JSON stream and asserts that it is the beginning of a new array.

Annotations
@Override
beginObjectback to summary
public void beginObject() throws IOException

Overrides com.google.gson.stream.JsonReader.beginObject.

Doc from com.google.gson.stream.JsonReader.beginObject.

Consumes the next token from the JSON stream and asserts that it is the beginning of a new object.

Annotations
@Override
closeback to summary
public void close() throws IOException

Overrides com.google.gson.stream.JsonReader.close.

Implements java.io.Closeable.close.

Doc from com.google.gson.stream.JsonReader.close.

Closes this JSON reader and the underlying Reader.

Using the JSON reader after it has been closed will throw an IllegalStateException in most cases.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Closeable.close.

if an I/O error occurs

endArrayback to summary
public void endArray() throws IOException

Overrides com.google.gson.stream.JsonReader.endArray.

Doc from com.google.gson.stream.JsonReader.endArray.

Consumes the next token from the JSON stream and asserts that it is the end of the current array.

Annotations
@Override
endObjectback to summary
public void endObject() throws IOException

Overrides com.google.gson.stream.JsonReader.endObject.

Doc from com.google.gson.stream.JsonReader.endObject.

Consumes the next token from the JSON stream and asserts that it is the end of the current object.

Annotations
@Override
expectback to summary
private void expect(JsonToken expected) throws IOException
getPathback to summary
private String getPath(boolean usePreviousPath)

Hides com.google.gson.stream.JsonReader.getPath.

getPathback to summary
public String getPath()

Overrides com.google.gson.stream.JsonReader.getPath.

Doc from com.google.gson.stream.JsonReader.getPath.

Returns a JSONPath in dot-notation to the next (or current) location in the JSON document. That means:

  • 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.

Annotations
@Override
getPreviousPathback to summary
public String getPreviousPath()

Overrides com.google.gson.stream.JsonReader.getPreviousPath.

Doc from com.google.gson.stream.JsonReader.getPreviousPath.

Returns a JSONPath in dot-notation to the previous (or current) location in the JSON document. That means:

  • 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.

Annotations
@Override
hasNextback to summary
public boolean hasNext() throws IOException

Overrides com.google.gson.stream.JsonReader.hasNext.

Doc from com.google.gson.stream.JsonReader.hasNext.

Returns true if the current array or object has another element.

Annotations
@Override
locationStringback to summary
private String locationString()

Hides com.google.gson.stream.JsonReader.locationString.

nextBooleanback to summary
public boolean nextBoolean() throws IOException

Overrides com.google.gson.stream.JsonReader.nextBoolean.

Doc from com.google.gson.stream.JsonReader.nextBoolean.

Returns the boolean value of the next token, consuming it.

Annotations
@Override
nextDoubleback to summary
public double nextDouble() throws IOException

Overrides com.google.gson.stream.JsonReader.nextDouble.

Doc from com.google.gson.stream.JsonReader.nextDouble.

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).

Annotations
@Override
nextIntback to summary
public int nextInt() throws IOException

Overrides com.google.gson.stream.JsonReader.nextInt.

Doc from com.google.gson.stream.JsonReader.nextInt.

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.

Annotations
@Override
nextJsonElementback to summary
pack-priv JsonElement nextJsonElement() throws IOException
nextLongback to summary
public long nextLong() throws IOException

Overrides com.google.gson.stream.JsonReader.nextLong.

Doc from com.google.gson.stream.JsonReader.nextLong.

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.

Annotations
@Override
nextNameback to summary
private String nextName(boolean skipName) throws IOException
nextNameback to summary
public String nextName() throws IOException

Overrides com.google.gson.stream.JsonReader.nextName.

Doc from com.google.gson.stream.JsonReader.nextName.

Returns the next token, a property name, and consumes it.

Annotations
@Override
nextNullback to summary
public void nextNull() throws IOException

Overrides com.google.gson.stream.JsonReader.nextNull.

Doc from com.google.gson.stream.JsonReader.nextNull.

Consumes the next token from the JSON stream and asserts that it is a literal null.

Annotations
@Override
nextStringback to summary
public String nextString() throws IOException

Overrides com.google.gson.stream.JsonReader.nextString.

Doc from com.google.gson.stream.JsonReader.nextString.

Returns the string value of the next token, consuming it. If the next token is a number, this method will return its string form.

Annotations
@Override
peekback to summary
public JsonToken peek() throws IOException

Overrides com.google.gson.stream.JsonReader.peek.

Doc from com.google.gson.stream.JsonReader.peek.

Returns the type of the next token without consuming it.

Annotations
@Override
peekStackback to summary
private Object peekStack()
popStackback to summary
private Object popStack()
Annotations
@CanIgnoreReturnValue
promoteNameToValueback to summary
public void promoteNameToValue() throws IOException
pushback to summary
private void push(Object newTop)
skipValueback to summary
public void skipValue() throws IOException

Overrides com.google.gson.stream.JsonReader.skipValue.

Doc from com.google.gson.stream.JsonReader.skipValue.

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.
Annotations
@Override
toStringback to summary
public String toString()

Overrides com.google.gson.stream.JsonReader.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override