Package com.bfo.json

Class JsonBuilder

java.lang.Object
com.bfo.json.JsonBuilder
All Implemented Interfaces:
JsonStream

public class JsonBuilder extends Object implements JsonStream
A JsonStream that can be used to build a Json object by calling build() when complete. Extending this class and overriding the various create... method can be used for special processing, such as storing large strings or buffers on disk, for example
 import java.lang.ref.Cleaner;
 import java.io.*;
 class StoringJsonBuilder extends JsonBuilder {
     final Cleaner cleaner = Cleaner.create();
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.bfo.json.JsonStream

    JsonStream.Event
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    If the stream is complete, return the Json object created by this builder, or null if the builder is incomplete
    boolean
    Process an event.
    boolean
    Return true if any objects being created will be added to a list
    boolean
    Return true if any objects being created are being added to a map
    Return the list of currently open keys as a stack, with the current one at the end of the list.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.bfo.json.JsonStream

    isSorted, reset
  • Constructor Details

    • JsonBuilder

      public JsonBuilder()
  • Method Details

    • build

      public Json build()
      If the stream is complete, return the Json object created by this builder, or null if the builder is incomplete
    • isList

      public boolean isList()
      Return true if any objects being created will be added to a list
    • isMap

      public boolean isMap()
      Return true if any objects being created are being added to a map
    • keys

      public List<Object> keys()
      Return the list of currently open keys as a stack, with the current one at the end of the list. The list is a copy and may be modified.
      Returns:
      the list of keys
    • event

      public boolean event(JsonStream.Event event) throws IOException
      Description copied from interface: JsonStream
      Process an event. Return true if the stream has completed. Any events submitted after this will cause an error
      Specified by:
      event in interface JsonStream
      Returns:
      true if the stream has completed
      Throws:
      IOException