Interface JsonReader

All Known Implementing Classes:
DefaultJsonReader, NonBufferedJsonReader

public interface JsonReader

JsonReader interface.

Version:
$Id: $
Author:
nicolasmorel
  • Method Summary

    Modifier and Type Method Description
    void beginArray()
    Consumes the next token from the JSON stream and asserts that it is the beginning of a new array.
    void beginObject()
    Consumes the next token from the JSON stream and asserts that it is the beginning of a new object.
    void close()
    Closes this JSON reader and the underlying Reader.
    void endArray()
    Consumes the next token from the JSON stream and asserts that it is the end of the current array.
    void endObject()
    Consumes the next token from the JSON stream and asserts that it is the end of the current object.
    int getColumnNumber()
    getColumnNumber
    java.lang.String getInput()
    getInput
    int getLineNumber()
    getLineNumber
    boolean hasNext()
    Returns true if the current array or object has another element.
    boolean nextBoolean()
    Returns the boolean value of the next token, consuming it.
    double nextDouble()
    Returns the double value of the next token, consuming it.
    int nextInt()
    Returns the int value of the next token, consuming it.
    long nextLong()
    Returns the long value of the next token, consuming it.
    java.lang.String nextName()
    Returns the next token, a property name, and consumes it.
    void nextNull()
    Consumes the next token from the JSON stream and asserts that it is a literal null.
    java.lang.Number nextNumber()
    Returns the Number value of the next token, consuming it.
    java.lang.String nextString()
    Returns the string value of the next token, consuming it.
    java.lang.String nextValue()
    Reads the next value recursively and returns it as a String.
    JsonToken peek()
    Returns the type of the next token without consuming it.
    void setLenient​(boolean lenient)
    Configure this parser to be be liberal in what it accepts.
    void skipValue()
    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 NaNs or infinities.
      • 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.
    • 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 JsonToken object.
    • nextName

      java.lang.String nextName()
      Returns the next token, a property name, and consumes it.
      Returns:
      a String object.
    • nextString

      java.lang.String nextString()
      Returns the string value of the next token, consuming it. If the next token is a number, this method will return its string form.
      Returns:
      a String object.
      Throws:
      java.lang.IllegalStateException - if the next token is not a string or if this reader is closed.
    • nextBoolean

      boolean nextBoolean()
      Returns the boolean value 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 the double value of the next token, consuming it. If the next token is a string, this method will attempt to parse it as a double using Double.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 the long value 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 Java long, 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 the int value 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 Java int, 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 underlying Reader.
    • 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 String object.
    • getLineNumber

      int getLineNumber()

      getLineNumber

      Returns:
      a int.
    • getColumnNumber

      int getColumnNumber()

      getColumnNumber

      Returns:
      a int.
    • getInput

      java.lang.String getInput()

      getInput

      Returns:
      a String object.
    • nextNumber

      java.lang.Number nextNumber()
      Returns the Number value 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 a BigInteger. For decimal number, a double is returned. If the next token's numeric value cannot be exactly represented by a Java Number, this method throws.
      Returns:
      a Number object.
      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.