Enum Class JsonToken
- All Implemented Interfaces:
Serializable, Comparable<JsonToken>, Constable
JSON Token - Token Types for Streaming JSON Parser
JSON 令牌 - 流式 JSON 解析器的令牌类型
This enum represents the different token types that can be encountered when parsing JSON using a streaming parser.
此枚举表示使用流式解析器解析 JSON 时可能遇到的不同令牌类型。
Example | 示例:
try (JsonReader reader = OpenJson.createReader(inputStream)) {
while (reader.hasNext()) {
JsonToken token = reader.peek();
switch (token) {
case START_OBJECT -> reader.beginObject();
case NAME -> {
String name = reader.nextName();
System.out.println("Field: " + name);
}
case STRING -> System.out.println("Value: " + reader.nextString());
case END_OBJECT -> reader.endObject();
}
}
}
Features | 主要功能:
- Enumeration of all JSON token types - 所有JSON令牌类型的枚举
- Token classification (scalar, structure, value) - 令牌分类(标量、结构、值)
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: N/A - 空值安全: 不适用
- Since:
- JDK 25, opencode-base-json V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionA JSON boolean value (true or false).End of a JSON array (]).End of JSON document.End of a JSON object (}).A JSON property name.Not available - parser needs to be advanced.A JSON null value.A JSON number value.Start of a JSON array ([).Start of a JSON object ({).A JSON string value. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether this is a numeric token.booleanReturns whether this token represents a scalar value.booleanReturns whether this token ends a structured value (object or array).booleanReturns whether this token starts a structured value (object or array).booleanisValue()Returns whether this token represents any value (scalar or structured).static JsonTokenReturns the enum constant of this class with the specified name.static JsonToken[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
START_OBJECT
Start of a JSON object ({). JSON 对象的开始 ({)。 -
END_OBJECT
End of a JSON object (}). JSON 对象的结束 (})。 -
START_ARRAY
Start of a JSON array ([). JSON 数组的开始 ([)。 -
END_ARRAY
End of a JSON array (]). JSON 数组的结束 (])。 -
NAME
A JSON property name. JSON 属性名。 -
STRING
A JSON string value. JSON 字符串值。 -
NUMBER
A JSON number value. JSON 数字值。 -
BOOLEAN
A JSON boolean value (true or false). JSON 布尔值 (true 或 false)。 -
NULL
A JSON null value. JSON null 值。 -
END_DOCUMENT
End of JSON document. JSON 文档结束。 -
NOT_AVAILABLE
Not available - parser needs to be advanced. 不可用 - 解析器需要前进。
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
isStructureStart
public boolean isStructureStart()Returns whether this token starts a structured value (object or array). 返回此令牌是否开始一个结构化值(对象或数组)。- Returns:
- true if START_OBJECT or START_ARRAY - 如果是 START_OBJECT 或 START_ARRAY 则返回 true
-
isStructureEnd
public boolean isStructureEnd()Returns whether this token ends a structured value (object or array). 返回此令牌是否结束一个结构化值(对象或数组)。- Returns:
- true if END_OBJECT or END_ARRAY - 如果是 END_OBJECT 或 END_ARRAY 则返回 true
-
isScalarValue
public boolean isScalarValue()Returns whether this token represents a scalar value. 返回此令牌是否表示标量值。- Returns:
- true if STRING, NUMBER, BOOLEAN, or NULL - 如果是 STRING、NUMBER、BOOLEAN 或 NULL 则返回 true
-
isValue
public boolean isValue()Returns whether this token represents any value (scalar or structured). 返回此令牌是否表示任何值(标量或结构化)。- Returns:
- true if this is a value token - 如果是值令牌则返回 true
-
isNumeric
public boolean isNumeric()Returns whether this is a numeric token. 返回此令牌是否为数字令牌。- Returns:
- true if NUMBER - 如果是 NUMBER 则返回 true
-