Annotation Interface JsonIdentityInfo


@Target({TYPE,FIELD,METHOD}) @Retention(RUNTIME) @Documented public @interface JsonIdentityInfo
JSON Identity Info - Handles Object Identity for Circular References JSON 身份信息 - 处理循环引用的对象身份

This annotation enables id-based serialization to handle circular references and shared object graphs. On first encounter, the full object is serialized along with an identity property. Subsequent references serialize only the ID.

此注解启用基于 ID 的序列化来处理循环引用和共享对象图。 首次遇到时,完整对象与身份属性一起序列化。后续引用仅序列化 ID。

Example | 示例:

@JsonIdentityInfo(
    generator = ObjectIdGenerators.IntSequenceGenerator.class,
    property = "@id"
)
public class Node {
    private String name;
    private List<Node> children;
    private Node parent;
}

Features | 主要功能:

  • Pluggable ID generators (integer, UUID, property, string) - 可插拔 ID 生成器(整数、UUID、属性、字符串)
  • Customizable identity property name - 可自定义身份属性名
  • Scoped uniqueness for ID isolation - 作用域唯一性实现 ID 隔离
  • Pluggable ID resolver for custom lookup strategies - 可插拔 ID 解析器支持自定义查找策略

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:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Class<? extends ObjectIdGenerator<?>>
    The object ID generator class to use for producing identifiers.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The name of the JSON property used to store the object identity.
    The resolver class used to look up previously seen objects by their ID.
    The scope class for determining ID uniqueness boundaries.
  • Element Details

    • generator

      Class<? extends ObjectIdGenerator<?>> generator
      The object ID generator class to use for producing identifiers. 用于生成标识符的对象 ID 生成器类。
      Returns:
      the generator class - 生成器类
    • property

      String property
      The name of the JSON property used to store the object identity. 用于存储对象身份的 JSON 属性名称。
      Returns:
      the property name - 属性名称
      Default:
      "@id"
    • scope

      Class<?> scope
      The scope class for determining ID uniqueness boundaries. 用于确定 ID 唯一性边界的作用域类。

      Void.class indicates global scope (default).

      Void.class 表示全局作用域(默认值)。

      Returns:
      the scope class - 作用域类
      Default:
      java.lang.Void.class
    • resolver

      Class<? extends ObjectIdResolver> resolver
      The resolver class used to look up previously seen objects by their ID. 用于按 ID 查找先前遇到的对象的解析器类。
      Returns:
      the resolver class - 解析器类
      Default:
      cloud.opencode.base.json.identity.SimpleObjectIdResolver.class