Class JsonParser

java.lang.Object
uk.blankaspect.common.json.JsonParser

public class JsonParser extends Object
This class implements a parser that transforms JSON text into a tree of values that are represented by nodes. The input text of the parser is expected to conform to the JSON grammar as specified in the following documents:

The parser is implemented in the parse(Reader) method as a finite-state machine (FSM) that terminates with an exception at the first error in the input text. The FSM combines the lexical analysis and parsing of the input text with the generation of the output (a tree of nodes that represent JSON values).

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    This class implements an exception that is thrown if an error occurs when parsing JSON text.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of a JSON parser.
  • Method Summary

    Modifier and Type
    Method
    Description
    parse(InputStream inputStream)
    Parses the text that is composed of characters that are read from the specified byte stream using the UTF-8 character encoding.
    parse(InputStream inputStream, Charset encoding)
    Parses the text that is composed of characters that are read from the specified byte stream using the specified character encoding.
    parse(Reader inputStream)
    Parses the text that is composed of characters that are read from the specified input stream.
    Parses the specified text.
    void
    setStoreExcessiveIntegerAsFP(boolean storeExcessiveIntegerAsFP)
    Sets or clears the flag that determines whether a JSON number that is deemed to be an integer but is too large to be stored as a signed 64-bit integer (ie, a long) will be stored as a double-precision floating-point number (ie, a double).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JsonParser

      public JsonParser()
      Creates a new instance of a JSON parser.
  • Method Details

    • setStoreExcessiveIntegerAsFP

      public void setStoreExcessiveIntegerAsFP(boolean storeExcessiveIntegerAsFP)
      Sets or clears the flag that determines whether a JSON number that is deemed to be an integer but is too large to be stored as a signed 64-bit integer (ie, a long) will be stored as a double-precision floating-point number (ie, a double).
      Parameters:
      storeExcessiveIntegerAsFP - if true a JSON number that is deemed to be an integer but is too large for a long will be stored as a double.
    • parse

      Parses the specified text. If the text conforms to the JSON grammar, this method transforms it into a tree of nodes that represent JSON values and returns the root of the tree.
      Parameters:
      text - the text that will be parsed as JSON text.
      Returns:
      the tree of JSON values that was created from parsing text.
      Throws:
      JsonParser.ParseException - if an error occurred when parsing the input text.
    • parse

      public AbstractNode parse(InputStream inputStream) throws JsonParser.ParseException
      Parses the text that is composed of characters that are read from the specified byte stream using the UTF-8 character encoding. If the text conforms to the JSON grammar, this method transforms it into a tree of nodes that represent JSON values and returns the root of the tree.
      Parameters:
      inputStream - the byte stream from which the JSON text will be read.
      Returns:
      the tree of JSON values that was created from parsing the text that was read from inputStream.
      Throws:
      JsonParser.ParseException - if an error occurred when parsing the input text.
    • parse

      public AbstractNode parse(InputStream inputStream, Charset encoding) throws JsonParser.ParseException
      Parses the text that is composed of characters that are read from the specified byte stream using the specified character encoding. If the text conforms to the JSON grammar, this method transforms it into a tree of nodes that represent JSON values and returns the root of the tree.
      Parameters:
      inputStream - the byte stream from which the JSON text will be read.
      encoding - the character encoding of inputStream; if null, the UTF-8 encoding will be used.
      Returns:
      the tree of JSON values that was created from parsing the text that was read from inputStream.
      Throws:
      JsonParser.ParseException - if an error occurred when parsing the input text.
    • parse

      public AbstractNode parse(Reader inputStream) throws JsonParser.ParseException
      Parses the text that is composed of characters that are read from the specified input stream. If the text conforms to the JSON grammar, this method transforms it into a tree of nodes that represent JSON values and returns the root of the tree.
      Parameters:
      inputStream - the character stream from which the JSON text will be read.
      Returns:
      the tree of JSON values that was created from parsing the text that was read from inputStream.
      Throws:
      JsonParser.ParseException - if an error occurred when parsing the input text.