Enum Class JsonToken

java.lang.Object
java.lang.Enum<JsonToken>
cloud.opencode.base.json.stream.JsonToken
All Implemented Interfaces:
Serializable, Comparable<JsonToken>, Constable

public enum JsonToken extends Enum<JsonToken>
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:
  • Enum Constant Details

    • START_OBJECT

      public static final JsonToken START_OBJECT
      Start of a JSON object ({). JSON 对象的开始 ({)。
    • END_OBJECT

      public static final JsonToken END_OBJECT
      End of a JSON object (}). JSON 对象的结束 (})。
    • START_ARRAY

      public static final JsonToken START_ARRAY
      Start of a JSON array ([). JSON 数组的开始 ([)。
    • END_ARRAY

      public static final JsonToken END_ARRAY
      End of a JSON array (]). JSON 数组的结束 (])。
    • NAME

      public static final JsonToken NAME
      A JSON property name. JSON 属性名。
    • STRING

      public static final JsonToken STRING
      A JSON string value. JSON 字符串值。
    • NUMBER

      public static final JsonToken NUMBER
      A JSON number value. JSON 数字值。
    • BOOLEAN

      public static final JsonToken BOOLEAN
      A JSON boolean value (true or false). JSON 布尔值 (true 或 false)。
    • NULL

      public static final JsonToken NULL
      A JSON null value. JSON null 值。
    • END_DOCUMENT

      public static final JsonToken END_DOCUMENT
      End of JSON document. JSON 文档结束。
    • NOT_AVAILABLE

      public static final JsonToken NOT_AVAILABLE
      Not available - parser needs to be advanced. 不可用 - 解析器需要前进。
  • Method Details

    • values

      public static JsonToken[] 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

      public static JsonToken valueOf(String name)
      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 name
      NullPointerException - 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