Class ConfigBinder
java.lang.Object
cloud.opencode.base.yml.bind.ConfigBinder
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 Summary
Modifier and TypeMethodDescriptionstatic <T> Tbind(PropertySource source, Class<T> clazz) Binds PropertySource to a class 将 PropertySource 绑定到类static <T> Tbind(PropertySource source, String prefix, Class<T> clazz) Binds PropertySource with prefix to a class 将带前缀的 PropertySource 绑定到类static <T> TBinds YAML content to a class 将 YAML 内容绑定到类static <T> TBinds YAML content with prefix to a class 将带前缀的 YAML 内容绑定到类static <T> TBinds a map to a class 将 Map 绑定到类
-
Method Details
-
bind
-
bind
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
Binds PropertySource to a class 将 PropertySource 绑定到类- Type Parameters:
T- type parameter | 类型参数- Parameters:
source- PropertySource | 属性源clazz- target class | 目标类- Returns:
- bound object | 绑定的对象
-
bind
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
-