Interface JsonTypeAdapterFactory


public interface JsonTypeAdapterFactory
JSON Type Adapter Factory - Factory for Creating Type Adapters JSON 类型适配器工厂 - 创建类型适配器的工厂

This interface defines a factory for creating JsonTypeAdapter instances based on the target type. Implementations can provide adapters for families of types (e.g., all enums, all collections).

此接口定义了基于目标类型创建 JsonTypeAdapter 实例的工厂。 实现可以为类型族提供适配器(例如所有枚举、所有集合)。

Example | 示例:

JsonTypeAdapterFactory factory = new JsonTypeAdapterFactory() {
    @Override
    public <T> JsonTypeAdapter<T> create(Class<T> type) {
        if (type.isEnum()) {
            return createEnumAdapter(type);
        }
        return null; // not supported
    }
};

Features | 主要功能:

  • Dynamic adapter creation for type families - 为类型族动态创建适配器
  • Returns null when the factory cannot handle a type - 当工厂无法处理类型时返回 null

Security | 安全性:

  • Thread-safe: Implementation-dependent - 线程安全: 取决于实现
  • Null-safe: Returns null for unsupported types - 空值安全: 对不支持的类型返回 null
Since:
JDK 25, opencode-base-json V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    create(Class<T> type)
    Creates a type adapter for the given type.
  • Method Details

    • create

      <T> JsonTypeAdapter<T> create(Class<T> type)
      Creates a type adapter for the given type. 为给定类型创建类型适配器。
      Type Parameters:
      T - the type parameter - 类型参数
      Parameters:
      type - the target type - 目标类型
      Returns:
      the adapter, or null if this factory does not support the type 适配器,如果此工厂不支持该类型则返回 null