- All Implemented Interfaces:
JsonParser
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 Summary
Modifier and TypeMethodDescriptionbooleanChecks if the current position contains a null value.voidClears the current mark.static ObjectStartParsercreate(JsonParser parser) Create a new JSON parser that pretends to be at the beginning of an object.createException(String message) Create a JsonException with the given message.createException(String message, byte c) Create a JsonException with the given message and found byte information.byteReturn the last byte that was read from the stream.booleanhasNext()Checks if there are more tokens available in the JSON stream.voidmark()Marks the current position in the JSON.byteReads the next JSON token without consuming it.Reads a numeric value asBigDecimal.Reads a numeric value asBigInteger.byte[]Reads a binary value.booleanReads a boolean value from the current position.bytereadByte()Reads a numeric value as a byte.charreadChar()Reads a char value from the current position.doubleReads a numeric value as a double.floatReads a numeric value as a float.intreadInt()Reads a numeric value as an int.Reads a JSON array from the current position.Reads a JSON number value from the current position.Reads a JSON object from the current position.Reads a JSON string value from the current position.Reads a complete JSON value from the current position.longreadLong()Reads a numeric value as a long.shortReads a numeric value as a short.Reads a string value from the current position.intReads a string value and returns its FNV-1a hash.voidResets the parser position to the previously marked position.voidskip()Skips the current JSON value without parsing it.
-
Method Details
-
create
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:JsonParserChecks 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:
hasNextin interfaceJsonParser- Returns:
- true if more tokens are available, false if end of stream is reached
-
nextToken
public byte nextToken()Description copied from interface:JsonParserReads 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:
nextTokenin interfaceJsonParser- Returns:
- the byte value of the next token
-
currentByte
public byte currentByte()Description copied from interface:JsonParserReturn 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:
currentBytein interfaceJsonParser- Returns:
- the last byte read, or 0 if no bytes have been read yet
-
readJsonValue
Description copied from interface:JsonParserReads 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:
readJsonValuein interfaceJsonParser- Returns:
- the parsed JsonValue
- See Also:
-
readJsonObject
Description copied from interface:JsonParserReads 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:
readJsonObjectin interfaceJsonParser- Returns:
- the parsed JsonObject
- See Also:
-
readJsonArray
Description copied from interface:JsonParserReads 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:
readJsonArrayin interfaceJsonParser- Returns:
- the parsed JsonArray
- See Also:
-
readJsonString
Description copied from interface:JsonParserReads 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:
readJsonStringin interfaceJsonParser- Returns:
- the parsed JsonString
- See Also:
-
readJsonNumber
Description copied from interface:JsonParserReads 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:
readJsonNumberin interfaceJsonParser- Returns:
- the parsed JsonNumber
- See Also:
-
readString
Description copied from interface:JsonParserReads 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:
readStringin interfaceJsonParser- Returns:
- the string value
-
readStringAsHash
public int readStringAsHash()Description copied from interface:JsonParserReads 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:
readStringAsHashin interfaceJsonParser- Returns:
- the hash of the string value
-
readChar
public char readChar()Description copied from interface:JsonParserReads 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:
readCharin interfaceJsonParser- Returns:
- the char value
-
readBoolean
public boolean readBoolean()Description copied from interface:JsonParserReads 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:
readBooleanin interfaceJsonParser- Returns:
- the boolean value
-
readByte
public byte readByte()Description copied from interface:JsonParserReads a numeric value as a byte.This method expects the next token to be a number and converts it to a byte.
- Specified by:
readBytein interfaceJsonParser- Returns:
- the byte value
-
readShort
public short readShort()Description copied from interface:JsonParserReads a numeric value as a short.This method expects the next token to be a number and converts it to a short.
- Specified by:
readShortin interfaceJsonParser- Returns:
- the short value
-
readInt
public int readInt()Description copied from interface:JsonParserReads a numeric value as an int.This method expects the next token to be a number and converts it to an int.
- Specified by:
readIntin interfaceJsonParser- Returns:
- the int value
-
readLong
public long readLong()Description copied from interface:JsonParserReads a numeric value as a long.This method expects the next token to be a number and converts it to a long.
- Specified by:
readLongin interfaceJsonParser- Returns:
- the long value
-
readFloat
public float readFloat()Description copied from interface:JsonParserReads a numeric value as a float.This method expects the next token to be a number and converts it to a float.
- Specified by:
readFloatin interfaceJsonParser- Returns:
- the float value
-
readDouble
public double readDouble()Description copied from interface:JsonParserReads a numeric value as a double.This method expects the next token to be a number and converts it to a double.
- Specified by:
readDoublein interfaceJsonParser- Returns:
- the double value
-
readBigInteger
Description copied from interface:JsonParserReads a numeric value asBigInteger.- Specified by:
readBigIntegerin interfaceJsonParser- Returns:
- the big integer value
-
readBigDecimal
Description copied from interface:JsonParserReads a numeric value asBigDecimal.- Specified by:
readBigDecimalin interfaceJsonParser- Returns:
- the big decimal value
-
readBinary
public byte[] readBinary()Description copied from interface:JsonParserReads a binary value.- Specified by:
readBinaryin interfaceJsonParser- Returns:
- the decoded binary value
-
checkNull
public boolean checkNull()Description copied from interface:JsonParserChecks 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:
checkNullin interfaceJsonParser- Returns:
- true if the next value is null, false otherwise
-
skip
public void skip()Description copied from interface:JsonParserSkips 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:
skipin interfaceJsonParser
-
createException
Description copied from interface:JsonParserCreate a JsonException with the given message.- Specified by:
createExceptionin interfaceJsonParser- Parameters:
message- the exception message- Returns:
- a JsonException
-
createException
Description copied from interface:JsonParserCreate a JsonException with the given message and found byte information.- Specified by:
createExceptionin interfaceJsonParser- Parameters:
message- the exception messagec- the byte that caused the exception- Returns:
- a JsonException
-
mark
public void mark()Description copied from interface:JsonParserMarks 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:
markin interfaceJsonParser
-
clearMark
public void clearMark()Description copied from interface:JsonParserClears the current mark.This method clears any previously set mark. Should be always called when backtracking is no longer needed.
- Specified by:
clearMarkin interfaceJsonParser
-
resetToMark
public void resetToMark()Description copied from interface:JsonParserResets 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:
resetToMarkin interfaceJsonParser
-