Class JsonStructureParser

java.lang.Object
org.glassfish.json.JsonStructureParser
All Implemented Interfaces:
Closeable, AutoCloseable, JsonParser

class JsonStructureParser extends Object implements JsonParser
JsonParser implementation on top of JsonArray/JsonObject
  • Field Details

  • Constructor Details

    • JsonStructureParser

      JsonStructureParser(JsonArray array)
    • JsonStructureParser

      JsonStructureParser(JsonObject object)
  • Method Details

    • getString

      public String getString()
      Description copied from interface: JsonParser
      Returns a String for the name in a name/value pair, for a string value or a number value. This method should only be called when the parser state is JsonParser.Event.KEY_NAME, JsonParser.Event.VALUE_STRING, or JsonParser.Event.VALUE_NUMBER.
      Specified by:
      getString in interface JsonParser
      Returns:
      a name when the parser state is JsonParser.Event.KEY_NAME a string value when the parser state is JsonParser.Event.VALUE_STRING a number value when the parser state is JsonParser.Event.VALUE_NUMBER
    • isIntegralNumber

      public boolean isIntegralNumber()
      Description copied from interface: JsonParser
      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();
       }
       
       
      Specified by:
      isIntegralNumber in interface JsonParser
      Returns:
      true if this number is a integral number, otherwise false
    • getInt

      public int getInt()
      Description copied from interface: JsonParser
      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.
      Specified by:
      getInt in interface JsonParser
      Returns:
      an integer for a JSON number
      See Also:
    • getLong

      public long getLong()
      Description copied from interface: JsonParser
      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.
      Specified by:
      getLong in interface JsonParser
      Returns:
      a long for a JSON number
      See Also:
    • getBigDecimal

      public BigDecimal getBigDecimal()
      Description copied from interface: JsonParser
      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.
      Specified by:
      getBigDecimal in interface JsonParser
      Returns:
      a BigDecimal for a JSON number
    • getLocation

      public JsonLocation getLocation()
      Description copied from interface: JsonParser
      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).
      Specified by:
      getLocation in interface JsonParser
      Returns:
      a non-null location corresponding to the current parser state in JSON input source
    • hasNext

      public boolean hasNext()
      Description copied from interface: JsonParser
      Returns true if there are more parsing states. This method returns false if the parser reaches the end of the JSON text.
      Specified by:
      hasNext in interface JsonParser
      Returns:
      true if there are more parsing states.
    • next

      public JsonParser.Event next()
      Description copied from interface: JsonParser
      Returns the event for the next parsing state.
      Specified by:
      next in interface JsonParser
      Returns:
      the event for the next parsing state
    • transition

      private void transition()
    • close

      public void close()
      Description copied from interface: JsonParser
      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
      Specified by:
      close in interface JsonParser
    • skipObject

      public void skipObject()
      Description copied from interface: JsonParser
      Advance the parser to END_OBJECT. If the parser is in object context, i.e. it has previously encountered a START_OBJECT without encountering the corresponding END_OBJECT, the parser is advanced to the corresponding END_OBJECT. If the parser is not in any object context, nothing happens.
      Specified by:
      skipObject in interface JsonParser
    • skipArray

      public void skipArray()
      Description copied from interface: JsonParser
      Advance the parser to END_ARRAY. If the parser is in array context, i.e. it has previously encountered a START_ARRAY without encountering the corresponding END_ARRAY, the parser is advanced to the corresponding END_ARRAY. If the parser is not in any array context, nothing happens.
      Specified by:
      skipArray in interface JsonParser
    • getState

      private static JsonParser.Event getState(JsonValue value)