- All Implemented Interfaces:
JsonParser
This class is not thread safe.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if the current position contains a null value.voidClears the current mark.static JsonParsercreate(byte[] json) Create a Smile parser from in-memory Smile-encoded bytes.static JsonParsercreate(InputStream inputStream) Create a Smile parser from an input stream.static JsonParsercreate(InputStream inputStream, int bufferSize) Create a Smile parser from an input stream.createException(String message) Create a JsonException with the given message.createException(String message, Exception e) Create a JsonException with the given message and cause.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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.helidon.json.JsonParser
createException
-
Method Details
-
create
Create a Smile parser from in-memory Smile-encoded bytes.- Parameters:
json- Smile binary data- Returns:
- a new Smile parser instance
-
create
Create a Smile parser from an input stream.- Parameters:
inputStream- stream containing Smile data- Returns:
- a new Smile parser instance
-
create
Create a Smile parser from an input stream.- Parameters:
inputStream- stream containing Smile databufferSize- size of the internal streaming buffer- Returns:
- a new Smile parser instance
-
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.
- 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.
- 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.
- 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- Overrides:
readJsonValuein classJsonParserBase- 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- Overrides:
readJsonObjectin classJsonParserBase- 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- Overrides:
readJsonArrayin classJsonParserBase- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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. It also accepts quoted
NaN,Infinity, and-Infinityvalues emitted by the JSON generator.- 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. It also accepts quoted
NaN,Infinity, and-Infinityvalues emitted by the JSON generator.- Returns:
- the double value
-
readBigInteger
Description copied from interface:JsonParserReads a numeric value asBigInteger.- Returns:
- the big integer value
-
readBigDecimal
Description copied from interface:JsonParserReads a numeric value asBigDecimal.- Returns:
- the big decimal value
-
readBinary
public byte[] readBinary()Description copied from interface:JsonParserReads a binary value.- 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.
- 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.
-
createException
Description copied from interface:JsonParserCreate a JsonException with the given message.- Parameters:
message- the exception message- Returns:
- a JsonException
-
createException
Description copied from interface:JsonParserCreate a JsonException with the given message and cause.- Parameters:
message- the exception messagee- the cause- 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. -
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.
-
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.
-