Class ConfigBinder

java.lang.Object
cloud.opencode.base.yml.bind.ConfigBinder

public final class ConfigBinder extends Object
Config Binder - Binds YAML properties to Java objects 配置绑定器 - 将 YAML 属性绑定到 Java 对象

Provides flexible binding of YAML configuration to Java beans and records.

提供将 YAML 配置灵活绑定到 Java Bean 和 Record 的功能。

Features | 主要功能:

  • Bind YAML to Java beans and records - 将 YAML 绑定到 Java Bean 和 Record
  • Prefix-based binding for nested configs - 基于前缀的嵌套配置绑定
  • Automatic camelCase/kebab-case/snake_case name conversion - 自动驼峰/短横线/下划线命名转换
  • PropertySource abstraction for multiple config sources - 多配置源的 PropertySource 抽象

Usage Examples | 使用示例:

// Bind YAML to bean
DatabaseConfig config = ConfigBinder.bind(yamlContent, DatabaseConfig.class);

// Bind with prefix
ServerConfig server = ConfigBinder.bind(yamlContent, "server", ServerConfig.class);

// Bind from PropertySource
PropertySource source = PropertySource.fromYaml(yamlContent);
AppConfig app = ConfigBinder.bind(source, AppConfig.class);

Security | 安全性:

  • Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
  • Null-safe: Yes (returns null/default for null input) - 空值安全: 是(空输入返回 null/默认值)
Since:
JDK 25, opencode-base-yml V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • bind

      public static <T> T bind(String yamlContent, Class<T> clazz)
      Binds YAML content to a class 将 YAML 内容绑定到类
      Type Parameters:
      T - type parameter | 类型参数
      Parameters:
      yamlContent - YAML content | YAML 内容
      clazz - target class | 目标类
      Returns:
      bound object | 绑定的对象
    • bind

      public static <T> T bind(String yamlContent, String prefix, Class<T> clazz)
      Binds YAML content with prefix to a class 将带前缀的 YAML 内容绑定到类
      Type Parameters:
      T - type parameter | 类型参数
      Parameters:
      yamlContent - YAML content | YAML 内容
      prefix - property prefix | 属性前缀
      clazz - target class | 目标类
      Returns:
      bound object | 绑定的对象
    • bind

      public static <T> T bind(PropertySource source, Class<T> clazz)
      Binds PropertySource to a class 将 PropertySource 绑定到类
      Type Parameters:
      T - type parameter | 类型参数
      Parameters:
      source - PropertySource | 属性源
      clazz - target class | 目标类
      Returns:
      bound object | 绑定的对象
    • bind

      public static <T> T bind(PropertySource source, String prefix, Class<T> clazz)
      Binds PropertySource with prefix to a class 将带前缀的 PropertySource 绑定到类
      Type Parameters:
      T - type parameter | 类型参数
      Parameters:
      source - PropertySource | 属性源
      prefix - property prefix | 属性前缀
      clazz - target class | 目标类
      Returns:
      bound object | 绑定的对象
    • bind

      public static <T> T bind(Map<String,Object> properties, Class<T> clazz)
      Binds a map to a class 将 Map 绑定到类
      Type Parameters:
      T - type parameter | 类型参数
      Parameters:
      properties - property map | 属性映射
      clazz - target class | 目标类
      Returns:
      bound object | 绑定的对象