Class JsonStreamParser

  • All Implemented Interfaces:
    Iterator<JsonElement>

    public final class JsonStreamParser
    extends Object
    implements Iterator<JsonElement>
    A streaming parser that allows reading of multiple JsonElements from the specified reader asynchronously. The JSON data is parsed in lenient mode, see also JsonReader.setLenient(boolean).

    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();
       }
     }
     
    Since:
    1.4
    Author:
    Inderjeet Singh, Joel Leitch