Package org.dominokit.jacksonapt.stream
Interface JsonReader
- All Known Implementing Classes:
DefaultJsonReader,NonBufferedJsonReader
public interface JsonReader
JsonReader interface.
- Version:
- $Id: $
- Author:
- nicolasmorel
-
Method Summary
Modifier and Type Method Description voidbeginArray()Consumes the next token from the JSON stream and asserts that it is the beginning of a new array.voidbeginObject()Consumes the next token from the JSON stream and asserts that it is the beginning of a new object.voidclose()Closes this JSON reader and the underlyingReader.voidendArray()Consumes the next token from the JSON stream and asserts that it is the end of the current array.voidendObject()Consumes the next token from the JSON stream and asserts that it is the end of the current object.intgetColumnNumber()getColumnNumberjava.lang.StringgetInput()getInputintgetLineNumber()getLineNumberbooleanhasNext()Returns true if the current array or object has another element.booleannextBoolean()Returns thebooleanvalue of the next token, consuming it.doublenextDouble()Returns thedoublevalue of the next token, consuming it.intnextInt()Returns theintvalue of the next token, consuming it.longnextLong()Returns thelongvalue of the next token, consuming it.java.lang.StringnextName()Returns the next token, aproperty name, and consumes it.voidnextNull()Consumes the next token from the JSON stream and asserts that it is a literal null.java.lang.NumbernextNumber()Returns theNumbervalue of the next token, consuming it.java.lang.StringnextString()Returns thestringvalue of the next token, consuming it.java.lang.StringnextValue()Reads the next value recursively and returns it as a String.JsonTokenpeek()Returns the type of the next token without consuming it.voidsetLenient(boolean lenient)Configure this parser to be be liberal in what it accepts.voidskipValue()Skips the next value recursively.
-
Method Details
-
setLenient
void setLenient(boolean lenient)Configure this parser to be be liberal in what it accepts. By default, this parser is strict and only accepts JSON as specified by RFC 4627. Setting the parser to lenient causes it to ignore the following syntax errors:- Streams that start with the non-execute
prefix,
")]}'\n". - Streams that include multiple top-level values. With strict parsing, each stream must contain exactly one top-level value.
- Top-level values of any type. With strict parsing, the top-level value must be an object or an array.
- Numbers may be
NaNsorinfinities. - End of line comments starting with
//or#and ending with a newline character. - C-style comments starting with
/*and ending with*/. Such comments may not be nested. - Names that are unquoted or
'single quoted'. - Strings that are unquoted or
'single quoted'. - Array elements separated by
;instead of,. - Unnecessary array separators. These are interpreted as if null was the omitted value.
- Names and values separated by
=or=>instead of:. - Name/value pairs separated by
;instead of,.
- Parameters:
lenient- a boolean.
- Streams that start with the non-execute
prefix,
-
beginArray
void beginArray()Consumes the next token from the JSON stream and asserts that it is the beginning of a new array. -
endArray
void endArray()Consumes the next token from the JSON stream and asserts that it is the end of the current array. -
beginObject
void beginObject()Consumes the next token from the JSON stream and asserts that it is the beginning of a new object. -
endObject
void endObject()Consumes the next token from the JSON stream and asserts that it is the end of the current object. -
hasNext
boolean hasNext()Returns true if the current array or object has another element.- Returns:
- a boolean.
-
peek
JsonToken peek()Returns the type of the next token without consuming it.- Returns:
- a
JsonTokenobject.
-
nextName
java.lang.String nextName()Returns the next token, aproperty name, and consumes it.- Returns:
- a
Stringobject.
-
nextString
java.lang.String nextString()Returns thestringvalue of the next token, consuming it. If the next token is a number, this method will return its string form.- Returns:
- a
Stringobject. - Throws:
java.lang.IllegalStateException- if the next token is not a string or if this reader is closed.
-
nextBoolean
boolean nextBoolean()Returns thebooleanvalue of the next token, consuming it.- Returns:
- a boolean.
- Throws:
java.lang.IllegalStateException- if the next token is not a boolean or if this reader is closed.
-
nextNull
void nextNull()Consumes the next token from the JSON stream and asserts that it is a literal null.- Throws:
java.lang.IllegalStateException- if the next token is not null or if this reader is closed.
-
nextDouble
double nextDouble()Returns thedoublevalue of the next token, consuming it. If the next token is a string, this method will attempt to parse it as a double usingDouble.parseDouble(String).- Returns:
- a double.
- Throws:
java.lang.IllegalStateException- if the next token is not a literal value.java.lang.NumberFormatException- if the next literal value cannot be parsed as a double, or is non-finite.
-
nextLong
long nextLong()Returns thelongvalue of the next token, consuming it. If the next token is a string, this method will attempt to parse it as a long. If the next token's numeric value cannot be exactly represented by a Javalong, this method throws.- Returns:
- a long.
- Throws:
java.lang.IllegalStateException- if the next token is not a literal value.java.lang.NumberFormatException- if the next literal value cannot be parsed as a number, or exactly represented as a long.
-
nextInt
int nextInt()Returns theintvalue of the next token, consuming it. If the next token is a string, this method will attempt to parse it as an int. If the next token's numeric value cannot be exactly represented by a Javaint, this method throws.- Returns:
- a int.
- Throws:
java.lang.IllegalStateException- if the next token is not a literal value.java.lang.NumberFormatException- if the next literal value cannot be parsed as a number, or exactly represented as an int.
-
close
void close()Closes this JSON reader and the underlyingReader. -
skipValue
void skipValue()Skips the next value recursively. If it is an object or array, all nested elements are skipped. This method is intended for use when the JSON token stream contains unrecognized or unhandled values. -
nextValue
java.lang.String nextValue()Reads the next value recursively and returns it as a String. If it is an object or array, all nested elements are read.- Returns:
- a
Stringobject.
-
getLineNumber
int getLineNumber()getLineNumber
- Returns:
- a int.
-
getColumnNumber
int getColumnNumber()getColumnNumber
- Returns:
- a int.
-
getInput
java.lang.String getInput()getInput
- Returns:
- a
Stringobject.
-
nextNumber
java.lang.Number nextNumber()Returns theNumbervalue of the next token, consuming it. This method will attempt to return the best matching number. For non-decimal number, if it fits into an int, an int is returned, else a long else aBigInteger. For decimal number, a double is returned. If the next token's numeric value cannot be exactly represented by a JavaNumber, this method throws.- Returns:
- a
Numberobject. - Throws:
java.lang.IllegalStateException- if the next token is not a number.java.lang.NumberFormatException- if the next value cannot be parsed as a number.
-