Class YmlBinder

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

public final class YmlBinder extends Object
YML Binder - Binds YAML data to Java objects YML 绑定器 - 将 YAML 数据绑定到 Java 对象

This class provides data binding between YAML documents and Java objects.

此类提供 YAML 文档和 Java 对象之间的数据绑定。

Features | 主要功能:

  • Bind YAML documents to Java beans and records - 将 YAML 文档绑定到 Java Bean 和 Record
  • Path-based binding with prefix support - 基于路径的前缀绑定
  • Annotation-driven field mapping (@YmlProperty, @YmlAlias, @YmlIgnore) - 注解驱动的字段映射
  • Bidirectional: object to Map and back - 双向转换:对象到 Map 及反向

Usage Examples | 使用示例:

// Bind to class
ServerConfig config = YmlBinder.bind(document, ServerConfig.class);

// Bind with prefix
ServerConfig config = YmlBinder.bind(document, "server", ServerConfig.class);

// Convert object to map
Map<String, Object> map = YmlBinder.toMap(config);

Security | 安全性:

  • Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
  • Null-safe: Yes (returns null 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(YmlDocument document, Class<T> type)
      Binds YAML data to a Java object. 将 YAML 数据绑定到 Java 对象。
      Type Parameters:
      T - the type parameter | 类型参数
      Parameters:
      document - the YAML document | YAML 文档
      type - the target type | 目标类型
      Returns:
      the bound object | 绑定的对象
    • bind

      public static <T> T bind(YmlDocument document, String path, Class<T> type)
      Binds YAML data at a path to a Java object. 将指定路径的 YAML 数据绑定到 Java 对象。
      Type Parameters:
      T - the type parameter | 类型参数
      Parameters:
      document - the YAML document | YAML 文档
      path - the path prefix | 路径前缀
      type - the target type | 目标类型
      Returns:
      the bound object | 绑定的对象
    • bind

      public static <T> T bind(Object data, Class<T> type)
      Binds Map data to a Java object. 将 Map 数据绑定到 Java 对象。
      Type Parameters:
      T - the type parameter | 类型参数
      Parameters:
      data - the data map | 数据映射
      type - the target type | 目标类型
      Returns:
      the bound object | 绑定的对象
    • toMap

      public static Map<String,Object> toMap(Object object)
      Converts an object to a Map. 将对象转换为 Map。
      Parameters:
      object - the object | 对象
      Returns:
      the map representation | Map 表示