public final class

JsonStreamParser

extends Object
implements Iterator<E>
java.lang.Object
   ↳ com.google.gson.JsonStreamParser

Class Overview

A streaming parser that allows reading of multiple JsonElements from the specified reader asynchronously.

This class is conditionally thread-safe (see Item 70, Effective Java second edition). To properly use this class across multiple threads, you will need to add some external synchronization. For example:

 JsonStreamParser parser = new JsonStreamParser("['first'] {'second':10} 'third'");
 JsonElement element;
 synchronized (parser) {  // synchronize on an object shared by threads
   if (parser.hasNext()) {
     element = parser.next();
   }
 }
 

Summary

Public Constructors
JsonStreamParser(String json)
JsonStreamParser(Reader reader)
Public Methods
boolean hasNext()
Returns true if a JsonElement is available on the input for consumption
JsonElement next()
Returns the next available JsonElement on the reader.
void remove()
This optional Iterator method is not relevant for stream parsing and hence is not implemented.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.util.Iterator

Public Constructors

public JsonStreamParser (String json)

Parameters
json The string containing JSON elements concatenated to each other.

public JsonStreamParser (Reader reader)

Parameters
reader The data stream containing JSON elements concatenated to each other.

Public Methods

public boolean hasNext ()

Returns true if a JsonElement is available on the input for consumption

Returns
  • true if a JsonElement is available on the input, false otherwise

public JsonElement next ()

Returns the next available JsonElement on the reader. Null if none available.

Returns
  • the next available JsonElement on the reader. Null if none available.
Throws
JsonParseException if the incoming stream is malformed JSON.

public void remove ()

This optional Iterator method is not relevant for stream parsing and hence is not implemented.