Class JsonModule.SimpleModule

java.lang.Object
cloud.opencode.base.json.spi.JsonModule.SimpleModule
All Implemented Interfaces:
JsonModule
Enclosing interface:
JsonModule

public abstract static class JsonModule.SimpleModule extends Object implements JsonModule
Simple Module - Convenient Base Implementation of JsonModule 简单模块 - JsonModule 的便捷基础实现

Provides a convenient way to create modules by collecting adapters, factories, and mixins before registering them via setupModule(SetupContext).

提供一种便捷的方式来创建模块,在通过 setupModule(SetupContext) 注册之前收集适配器、工厂和混入。

Example | 示例:

SimpleModule module = new SimpleModule("custom", "1.0.0")
    .addAdapter(new MoneyAdapter())
    .addFactory(new EnumAdapterFactory())
    .addMixin(User.class, UserMixin.class);
Since:
JDK 25, opencode-base-json V1.0.0
Author:
Leon Soo www.LeonSoo.com
  • Constructor Details

    • SimpleModule

      protected SimpleModule(String name, String version)
      Constructs a SimpleModule with the given name and version. 使用给定的名称和版本构造 SimpleModule。
      Parameters:
      name - the module name - 模块名称
      version - the module version - 模块版本
  • Method Details

    • getName

      public String getName()
      Description copied from interface: JsonModule
      Returns the module name. 返回模块名称。
      Specified by:
      getName in interface JsonModule
      Returns:
      the module name - 模块名称
    • getVersion

      public String getVersion()
      Description copied from interface: JsonModule
      Returns the module version. 返回模块版本。
      Specified by:
      getVersion in interface JsonModule
      Returns:
      the module version - 模块版本
    • addAdapter

      public JsonModule.SimpleModule addAdapter(JsonTypeAdapter<?> adapter)
      Adds a type adapter to this module. 向此模块添加类型适配器。
      Parameters:
      adapter - the adapter to add - 要添加的适配器
      Returns:
      this module for chaining - 此模块,用于链式调用
    • addFactory

      public JsonModule.SimpleModule addFactory(JsonTypeAdapterFactory factory)
      Adds a type adapter factory to this module. 向此模块添加类型适配器工厂。
      Parameters:
      factory - the factory to add - 要添加的工厂
      Returns:
      this module for chaining - 此模块,用于链式调用
    • addMixin

      public JsonModule.SimpleModule addMixin(Class<?> target, Class<?> mixin)
      Adds a mixin mapping to this module. 向此模块添加混入映射。
      Parameters:
      target - the target class - 目标类
      mixin - the mixin class - 混入类
      Returns:
      this module for chaining - 此模块,用于链式调用
    • addKeyAdapter

      public JsonModule.SimpleModule addKeyAdapter(Class<?> type, JsonTypeAdapter<?> adapter)
      Adds a key adapter to this module. 向此模块添加键适配器。
      Parameters:
      type - the key type - 键类型
      adapter - the key adapter - 键适配器
      Returns:
      this module for chaining - 此模块,用于链式调用
    • getAdapters

      public List<JsonTypeAdapter<?>> getAdapters()
      Returns the registered adapters. 返回注册的适配器。
      Returns:
      unmodifiable list of adapters - 不可修改的适配器列表
    • getFactories

      public List<JsonTypeAdapterFactory> getFactories()
      Returns the registered factories. 返回注册的工厂。
      Returns:
      unmodifiable list of factories - 不可修改的工厂列表
    • getMixins

      public Map<Class<?>,Class<?>> getMixins()
      Returns the registered mixins. 返回注册的混入。
      Returns:
      unmodifiable map of mixins - 不可修改的混入映射
    • getKeyAdapters

      public Map<Class<?>, JsonTypeAdapter<?>> getKeyAdapters()
      Returns the registered key adapters. 返回注册的键适配器。
      Returns:
      unmodifiable map of key adapters - 不可修改的键适配器映射
    • setupModule

      public void setupModule(JsonModule.SetupContext context)
      Description copied from interface: JsonModule
      Configures the module using the provided setup context. 使用提供的设置上下文配置模块。
      Specified by:
      setupModule in interface JsonModule
      Parameters:
      context - the setup context for registering components - 用于注册组件的设置上下文
    • toString

      public String toString()
      Overrides:
      toString in class Object