Class JsonAdapterRegistry
java.lang.Object
cloud.opencode.base.json.adapter.JsonAdapterRegistry
JSON Adapter Registry - Registry for Custom Type Adapters
JSON 适配器注册表 - 自定义类型适配器的注册表
This class manages registration and lookup of custom type adapters for JSON serialization and deserialization.
此类管理 JSON 序列化和反序列化的自定义类型适配器的注册和查找。
Example | 示例:
// Register a custom adapter
JsonAdapterRegistry.register(new MoneyAdapter());
// Get adapter for a type
JsonTypeAdapter<Money> adapter = JsonAdapterRegistry.getAdapter(Money.class);
// Use adapter
JsonNode json = adapter.toJson(new Money(100, "USD"));
Money money = adapter.fromJson(json);
Features | 主要功能:
- Global and isolated adapter registries - 全局和隔离的适配器注册表
- Built-in adapters for common Java types - 常见Java类型的内置适配器
- Factory pattern for dynamic adapter creation - 动态适配器创建的工厂模式
Security | 安全性:
- Thread-safe: Implementation-dependent - 线程安全: 取决于实现
- Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
- Since:
- JDK 25, opencode-base-json V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAdapter factory interface for dynamic adapter creation.static final classIsolated adapter registry instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclear()Clears all custom adapters (keeps built-in).static JsonAdapterRegistry.RegistryCreates a new isolated registry.static <T> JsonTypeAdapter<T> getAdapter(Class<T> type) Gets an adapter for a type.static JsonTypeAdapter<?> getAdapter(Type type) Gets an adapter for a generic type.Returns all registered types.static booleanhasAdapter(Class<?> type) Checks if an adapter exists for a type.static <T> voidregister(JsonTypeAdapter<T> adapter) Registers a type adapter.static <T> voidregister(Class<T> type, JsonTypeAdapter<T> adapter) Registers an adapter for a specific type.static voidRegisters an adapter factory.static JsonTypeAdapter<?> unregister(Class<?> type) Unregisters an adapter for a type.
-
Method Details
-
register
Registers a type adapter. 注册类型适配器。- Type Parameters:
T- the type - 类型- Parameters:
adapter- the adapter to register - 要注册的适配器
-
register
Registers an adapter for a specific type. 为特定类型注册适配器。- Type Parameters:
T- the type - 类型- Parameters:
type- the type - 类型adapter- the adapter - 适配器
-
registerFactory
Registers an adapter factory. 注册适配器工厂。- Parameters:
factory- the factory - 工厂
-
getAdapter
Gets an adapter for a type. 获取类型的适配器。- Type Parameters:
T- the type - 类型- Parameters:
type- the type - 类型- Returns:
- the adapter, or null if not found - 适配器,如果未找到则返回 null
-
getAdapter
Gets an adapter for a generic type. 获取泛型类型的适配器。- Parameters:
type- the type - 类型- Returns:
- the adapter, or null if not found - 适配器,如果未找到则返回 null
-
hasAdapter
Checks if an adapter exists for a type. 检查类型是否存在适配器。- Parameters:
type- the type - 类型- Returns:
- true if adapter exists - 如果存在适配器则返回 true
-
unregister
Unregisters an adapter for a type. 注销类型的适配器。- Parameters:
type- the type - 类型- Returns:
- the removed adapter, or null - 移除的适配器,或 null
-
getRegisteredTypes
-
clear
public static void clear()Clears all custom adapters (keeps built-in). 清除所有自定义适配器(保留内置)。 -
createRegistry
Creates a new isolated registry. 创建新的隔离注册表。- Returns:
- a new registry instance - 新注册表实例
-