Class ObjectStartParser

java.lang.Object
io.helidon.json.ObjectStartParser
All Implemented Interfaces:
JsonParser

public final class ObjectStartParser extends Object implements JsonParser
An implementation of the JsonParser which enforces object start as the current value. Delegates all other calls to the provided JsonParser.

This module is incubating. These APIs may change in any version of Helidon, including backward incompatible changes.

  • Method Details

    • create

      public static ObjectStartParser create(JsonParser parser)
      Create a new JSON parser that pretends to be at the beginning of an object.

      This method wraps an existing parser to ensure that parsing begins at the start of a JSON object ('{'). It is expected the provided parser is at the key start or object end.

      Parameters:
      parser - the base parser to wrap
      Returns:
      a new ObjectStartParser instance that starts at object beginning
    • hasNext

      public boolean hasNext()
      Description copied from interface: JsonParser
      Checks if there are more tokens available in the JSON stream.

      This method should be called before attempting to read any tokens to avoid exceptions when reaching the end of the JSON content.

      Specified by:
      hasNext in interface JsonParser
      Returns:
      true if more tokens are available, false if end of stream is reached
    • nextToken

      public byte nextToken()
      Description copied from interface: JsonParser
      Reads the next JSON token without consuming it.

      This method advances the parser to the next significant token (skipping whitespace) but does not consume it. The token can then be read using appropriate read methods.

      Specified by:
      nextToken in interface JsonParser
      Returns:
      the byte value of the next token
    • currentByte

      public byte currentByte()
      Description copied from interface: JsonParser
      Return the last byte that was read from the stream.

      This method can be used to inspect the current parser position without advancing it. Useful for debugging or conditional parsing logic.

      Specified by:
      currentByte in interface JsonParser
      Returns:
      the last byte read, or 0 if no bytes have been read yet
    • readJsonValue

      public JsonValue readJsonValue()
      Description copied from interface: JsonParser
      Reads a complete JSON value from the current position.

      This method parses and returns the next complete JSON value (object, array, string, number, boolean, or null) from the current parser position.

      Specified by:
      readJsonValue in interface JsonParser
      Returns:
      the parsed JsonValue
      See Also:
    • readJsonObject

      public JsonObject readJsonObject()
      Description copied from interface: JsonParser
      Reads a JSON object from the current position.

      This method expects the next token to be an object start ('{') and parses the complete object including all nested values.

      Specified by:
      readJsonObject in interface JsonParser
      Returns:
      the parsed JsonObject
      See Also:
    • readJsonArray

      public JsonArray readJsonArray()
      Description copied from interface: JsonParser
      Reads a JSON array from the current position.

      This method expects the next token to be an array start ('[') and parses the complete array including all nested values.

      Specified by:
      readJsonArray in interface JsonParser
      Returns:
      the parsed JsonArray
      See Also:
    • readJsonString

      public JsonString readJsonString()
      Description copied from interface: JsonParser
      Reads a JSON string value from the current position.

      This method expects the next token to be a string and returns the parsed string value.

      Specified by:
      readJsonString in interface JsonParser
      Returns:
      the parsed JsonString
      See Also:
    • readJsonNumber

      public JsonNumber readJsonNumber()
      Description copied from interface: JsonParser
      Reads a JSON number value from the current position.

      This method expects the next token to be a number and returns the parsed numeric value.

      Specified by:
      readJsonNumber in interface JsonParser
      Returns:
      the parsed JsonNumber
      See Also:
    • readString

      public String readString()
      Description copied from interface: JsonParser
      Reads a string value from the current position. The value has to start and end with the ".

      This method expects the next token to be a string and returns the string content as a Java String.

      Specified by:
      readString in interface JsonParser
      Returns:
      the string value
    • readStringAsHash

      public int readStringAsHash()
      Description copied from interface: JsonParser
      Reads a string value and returns its FNV-1a hash.

      This method is optimized for performance when only string comparison is needed, avoiding string object allocation.

      Specified by:
      readStringAsHash in interface JsonParser
      Returns:
      the hash of the string value
    • readChar

      public char readChar()
      Description copied from interface: JsonParser
      Reads a char value from the current position. The value has to start and end with the ".

      This method expects the next token to be a string and returns the string content as a Java char value. It has to be one character.

      Specified by:
      readChar in interface JsonParser
      Returns:
      the char value
    • readBoolean

      public boolean readBoolean()
      Description copied from interface: JsonParser
      Reads a boolean value from the current position.

      This method expects the next token to be a boolean (true/false) and returns the corresponding Java boolean value.

      Specified by:
      readBoolean in interface JsonParser
      Returns:
      the boolean value
    • readByte

      public byte readByte()
      Description copied from interface: JsonParser
      Reads a numeric value as a byte.

      This method expects the next token to be a number and converts it to a byte.

      Specified by:
      readByte in interface JsonParser
      Returns:
      the byte value
    • readShort

      public short readShort()
      Description copied from interface: JsonParser
      Reads a numeric value as a short.

      This method expects the next token to be a number and converts it to a short.

      Specified by:
      readShort in interface JsonParser
      Returns:
      the short value
    • readInt

      public int readInt()
      Description copied from interface: JsonParser
      Reads a numeric value as an int.

      This method expects the next token to be a number and converts it to an int.

      Specified by:
      readInt in interface JsonParser
      Returns:
      the int value
    • readLong

      public long readLong()
      Description copied from interface: JsonParser
      Reads a numeric value as a long.

      This method expects the next token to be a number and converts it to a long.

      Specified by:
      readLong in interface JsonParser
      Returns:
      the long value
    • readFloat

      public float readFloat()
      Description copied from interface: JsonParser
      Reads a numeric value as a float.

      This method expects the next token to be a number and converts it to a float.

      Specified by:
      readFloat in interface JsonParser
      Returns:
      the float value
    • readDouble

      public double readDouble()
      Description copied from interface: JsonParser
      Reads a numeric value as a double.

      This method expects the next token to be a number and converts it to a double.

      Specified by:
      readDouble in interface JsonParser
      Returns:
      the double value
    • readBigInteger

      public BigInteger readBigInteger()
      Description copied from interface: JsonParser
      Reads a numeric value as BigInteger.
      Specified by:
      readBigInteger in interface JsonParser
      Returns:
      the big integer value
    • readBigDecimal

      public BigDecimal readBigDecimal()
      Description copied from interface: JsonParser
      Reads a numeric value as BigDecimal.
      Specified by:
      readBigDecimal in interface JsonParser
      Returns:
      the big decimal value
    • readBinary

      public byte[] readBinary()
      Description copied from interface: JsonParser
      Reads a binary value.
      Specified by:
      readBinary in interface JsonParser
      Returns:
      the decoded binary value
    • checkNull

      public boolean checkNull()
      Description copied from interface: JsonParser
      Checks if the current position contains a null value.

      This method peeks at the next value to determine if it's null and advances the parser position if it is.

      Specified by:
      checkNull in interface JsonParser
      Returns:
      true if the next value is null, false otherwise
    • skip

      public void skip()
      Description copied from interface: JsonParser
      Skips the current JSON value without parsing it.

      This method advances the parser past the current value (object, array, string, number, boolean, or null) without constructing Java objects. Useful for skipping unwanted parts of large JSON documents.

      Specified by:
      skip in interface JsonParser
    • createException

      public JsonException createException(String message)
      Description copied from interface: JsonParser
      Create a JsonException with the given message.
      Specified by:
      createException in interface JsonParser
      Parameters:
      message - the exception message
      Returns:
      a JsonException
    • createException

      public JsonException createException(String message, byte c)
      Description copied from interface: JsonParser
      Create a JsonException with the given message and found byte information.
      Specified by:
      createException in interface JsonParser
      Parameters:
      message - the exception message
      c - the byte that caused the exception
      Returns:
      a JsonException
    • mark

      public void mark()
      Description copied from interface: JsonParser
      Marks the current position in the JSON.

      This method saves the current parser position so it can be returned to later using JsonParser.resetToMark(). Useful for backtracking during parsing operations.

      Specified by:
      mark in interface JsonParser
    • clearMark

      public void clearMark()
      Description copied from interface: JsonParser
      Clears the current mark.

      This method clears any previously set mark. Should be always called when backtracking is no longer needed.

      Specified by:
      clearMark in interface JsonParser
    • resetToMark

      public void resetToMark()
      Description copied from interface: JsonParser
      Resets the parser position to the previously marked position.

      This method restores the parser to the position that was saved with JsonParser.mark(). Allows for backtracking to a previous parsing state.

      Specified by:
      resetToMark in interface JsonParser