Class SimpleObjectIdResolver
java.lang.Object
cloud.opencode.base.json.identity.SimpleObjectIdResolver
- All Implemented Interfaces:
ObjectIdResolver
Simple Object ID Resolver - Default HashMap-Based Identity Resolver
简单对象 ID 解析器 - 默认基于 HashMap 的身份解析器
A straightforward implementation of ObjectIdResolver that uses
a HashMap to store and retrieve object identity mappings.
Each deserialization context should use its own instance.
一个简单的 ObjectIdResolver 实现,使用 HashMap
存储和检索对象身份映射。每个反序列化上下文应使用自己的实例。
Example | 示例:
SimpleObjectIdResolver resolver = new SimpleObjectIdResolver();
ObjectIdGenerator.IdKey key = new ObjectIdGenerator.IdKey(User.class, Void.class, 42);
resolver.bindItem(key, user);
Object found = resolver.resolveId(key); // returns user
Security | 安全性:
- Thread-safe: No (single-threaded deserialization context) - 线程安全: 否(单线程反序列化上下文)
- Null-safe: Rejects null ID keys - 空值安全: 拒绝空 ID 键
- Since:
- JDK 25, opencode-base-json V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new SimpleObjectIdResolver with an empty identity map. -
Method Summary
Modifier and TypeMethodDescriptionvoidbindItem(ObjectIdGenerator.IdKey id, Object pojo) Binds an object identity key to a POJO instance.booleancanUseFor(ObjectIdResolver resolverType) Determines whether this resolver can be used interchangeably with another.newForDeserialization(Object context) Creates a new resolver instance for a deserialization context.Resolves an object identity key to a previously bound POJO instance.
-
Constructor Details
-
SimpleObjectIdResolver
public SimpleObjectIdResolver()Creates a new SimpleObjectIdResolver with an empty identity map. 创建一个具有空身份映射表的 SimpleObjectIdResolver。
-
-
Method Details
-
bindItem
Description copied from interface:ObjectIdResolverBinds an object identity key to a POJO instance. 将对象身份键绑定到 POJO 实例。- Specified by:
bindItemin interfaceObjectIdResolver- Parameters:
id- the identity key - 身份键pojo- the object instance to bind - 要绑定的对象实例
-
resolveId
Description copied from interface:ObjectIdResolverResolves an object identity key to a previously bound POJO instance. 将对象身份键解析为之前绑定的 POJO 实例。- Specified by:
resolveIdin interfaceObjectIdResolver- Parameters:
id- the identity key to resolve - 要解析的身份键- Returns:
- the bound object, or
nullif not found - 绑定的对象,未找到则返回 null
-
canUseFor
Description copied from interface:ObjectIdResolverDetermines whether this resolver can be used interchangeably with another. 确定此解析器是否可以与另一个互换使用。- Specified by:
canUseForin interfaceObjectIdResolver- Parameters:
resolverType- the other resolver to check compatibility with - 要检查兼容性的另一个解析器- Returns:
- true if compatible - 如果兼容则返回 true
-
newForDeserialization
Description copied from interface:ObjectIdResolverCreates a new resolver instance for a deserialization context. 为反序列化上下文创建新的解析器实例。- Specified by:
newForDeserializationin interfaceObjectIdResolver- Parameters:
context- the deserialization context - 反序列化上下文- Returns:
- a new resolver instance - 新的解析器实例
-