Package uk.blankaspect.common.json
Class JsonParser
java.lang.Object
uk.blankaspect.common.json.JsonParser
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
Modifier and TypeClassDescriptionstatic class
This class implements an exception that is thrown if an error occurs when parsing JSON text. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionparse
(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.Parses the text that is composed of characters that are read from the specified input stream.parse
(CharSequence text) 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, along
) will be stored as a double-precision floating-point number (ie, adouble
).
-
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, along
) will be stored as a double-precision floating-point number (ie, adouble
).- Parameters:
storeExcessiveIntegerAsFP
- iftrue
a JSON number that is deemed to be an integer but is too large for along
will be stored as adouble
.
-
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
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 ofinputStream
; ifnull
, 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
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.
-