Interface JsonParser

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static class  JsonParser.Event
      An event from JsonParser.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void close​()
      Closes this parser and frees any resources associated with the parser.
      java.math.BigDecimal getBigDecimal​()
      Returns a JSON number as a BigDecimal.
      int getInt​()
      Returns a JSON number as an integer.
      JsonLocation getLocation​()
      Return the location that corresponds to the parser's current state in the JSON input source.
      long getLong​()
      Returns a JSON number as a long.
      java.lang.String getString​()
      Returns a String for the name in a name/value pair, for a string value or a number value.
      boolean hasNext​()
      Returns true if there are more parsing states.
      boolean isIntegralNumber​()
      Returns true if the JSON number at the current parser state is a integral number.
      JsonParser.Event next​()
      Returns the event for the next parsing state.
    • Method Detail

      • hasNext

        boolean hasNext​()
        Returns true if there are more parsing states. This method returns false if the parser reaches the end of the JSON text.
        Returns:
        true if there are more parsing states.
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonParsingException - if the parser encounters invalid JSON when advancing to next state.
      • next

        JsonParser.Event next​()
        Returns the event for the next parsing state.
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonParsingException - if the parser encounters invalid JSON when advancing to next state.
        java.util.NoSuchElementException - if there are no more parsing states.
      • isIntegralNumber

        boolean isIntegralNumber​()
        Returns true if the JSON number at the current parser state is a integral number. A BigDecimal may be used to store the value internally and this method semantics are defined using its scale(). If the scale is zero, then it is considered integral type. This integral type information can be used to invoke an appropriate accessor method to obtain a numeric value as in the following example:
         
         JsonParser parser = ...
         if (parser.isIntegralNumber()) {
             parser.getInt();     // or other methods to get integral value
         } else {
             parser.getBigDecimal();
         }
         
         
        Returns:
        true if this number is a integral number, otherwise false
        Throws:
        java.lang.IllegalStateException - when the parser state is not VALUE_NUMBER
      • getInt

        int getInt​()
        Returns a JSON number as an integer. The returned value is equal to new BigDecimal(getString()).intValue(). Note that this conversion can lose information about the overall magnitude and precision of the number value as well as return a result with the opposite sign. This method should only be called when the parser state is JsonParser.Event.VALUE_NUMBER.
        Returns:
        an integer for a JSON number
        Throws:
        java.lang.IllegalStateException - when the parser state is not VALUE_NUMBER
        See Also:
        BigDecimal.intValue()
      • getLong

        long getLong​()
        Returns a JSON number as a long. The returned value is equal to new BigDecimal(getString()).longValue(). Note that this conversion can lose information about the overall magnitude and precision of the number value as well as return a result with the opposite sign. This method is only called when the parser state is JsonParser.Event.VALUE_NUMBER.
        Returns:
        a long for a JSON number
        Throws:
        java.lang.IllegalStateException - when the parser state is not VALUE_NUMBER
        See Also:
        BigDecimal.longValue()
      • getBigDecimal

        java.math.BigDecimal getBigDecimal​()
        Returns a JSON number as a BigDecimal. The BigDecimal is created using new BigDecimal(getString()). This method should only called when the parser state is JsonParser.Event.VALUE_NUMBER.
        Returns:
        a BigDecimal for a JSON number
        Throws:
        java.lang.IllegalStateException - when the parser state is not VALUE_NUMBER
      • getLocation

        JsonLocation getLocation​()
        Return the location that corresponds to the parser's current state in the JSON input source. The location information is only valid in the current parser state (or until the parser is advanced to a next state).
        Returns:
        a non-null location corresponding to the current parser state in JSON input source
      • close

        void close​()
        Closes this parser and frees any resources associated with the parser. This method closes the underlying input source.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)