Class ObjectIdGenerator<T>

java.lang.Object
cloud.opencode.base.json.identity.ObjectIdGenerator<T>
Type Parameters:
T - the type of generated identifiers - 生成的标识符类型
Direct Known Subclasses:
ObjectIdGenerators.IntSequenceGenerator, ObjectIdGenerators.PropertyGenerator, ObjectIdGenerators.StringIdGenerator, ObjectIdGenerators.UUIDGenerator

public abstract class ObjectIdGenerator<T> extends Object
Object ID Generator - Abstract Base for Generating Object Identifiers 对象 ID 生成器 - 生成对象标识符的抽象基类

This abstract class defines the contract for generating unique identifiers for objects during JSON serialization. Implementations provide specific strategies such as auto-increment integers, UUIDs, or property-based IDs.

此抽象类定义了在 JSON 序列化期间为对象生成唯一标识符的契约。 实现提供特定策略,如自增整数、UUID 或基于属性的 ID。

Example | 示例:

ObjectIdGenerator<Integer> gen = new ObjectIdGenerators.IntSequenceGenerator();
Integer id = gen.generateId(myObject);

Security | 安全性:

  • Thread-safe: Depends on implementation - 线程安全: 取决于实现
  • Null-safe: Implementations should document null behavior - 空值安全: 实现应说明空值行为
Since:
JDK 25, opencode-base-json V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • ObjectIdGenerator

      public ObjectIdGenerator()
  • Method Details

    • generateId

      public abstract T generateId(Object forPojo)
      Generates a unique identifier for the given object. 为给定对象生成唯一标识符。
      Parameters:
      forPojo - the object to generate an ID for - 要生成 ID 的对象
      Returns:
      the generated identifier - 生成的标识符
    • getScope

      public abstract Class<?> getScope()
      Returns the scope class used to determine ID uniqueness boundaries. 返回用于确定 ID 唯一性边界的作用域类。
      Returns:
      the scope class - 作用域类
    • canUseFor

      public abstract boolean canUseFor(ObjectIdGenerator<?> gen)
      Determines whether this generator can be used interchangeably with another. 确定此生成器是否可以与另一个互换使用。
      Parameters:
      gen - the other generator to check compatibility with - 要检查兼容性的另一个生成器
      Returns:
      true if compatible - 如果兼容则返回 true