javax.json.stream

Interface JsonParser

    • 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.
      • 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:
        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:
        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:
        IllegalStateException - when the parser state is not VALUE_NUMBER
        See Also:
        BigDecimal.longValue()
      • getBigDecimal

        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:
        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 AutoCloseable
        Specified by:
        close in interface Closeable
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)

Document created the 11/06/2005, last modified the 18/08/2025
Source of the printed document:https://www.gaudry.be/en/java-api-javaee-rf-javax/json/stream/jsonparser.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : https://docs.oracle.com/en/java/, Interface JsonParser

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author of this site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.