Interface YmlProvider


public interface YmlProvider
YAML Provider SPI Interface - Service provider interface for YAML processing YAML 提供者 SPI 接口 - YAML 处理的服务提供者接口

This interface defines the contract for YAML processing providers. Implementations can use different underlying libraries like SnakeYAML.

此接口定义了 YAML 处理提供者的契约。 实现可以使用不同的底层库,如 SnakeYAML。

Features | 主要功能:

  • Load YAML from strings, streams, and to typed objects - 从字符串、流加载 YAML 及到类型化对象
  • Dump objects to YAML strings, streams, and writers - 将对象输出到 YAML 字符串、流和写入器
  • Tree parsing and validation support - 树解析和验证支持
  • Multi-document YAML support - 多文档 YAML 支持

Usage Examples | 使用示例:

// Register via SPI: META-INF/services/cloud.opencode.base.yml.spi.YmlProvider
YmlProvider provider = YmlProviderFactory.getProvider();
Map<String, Object> data = provider.load("key: value");

Security | 安全性:

  • Thread-safe: Depends on implementation - 线程安全: 取决于实现
  • Null-safe: Depends on implementation - 空值安全: 取决于实现
Since:
JDK 25, opencode-base-yml V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • getName

      String getName()
      Gets the provider name. 获取提供者名称。
      Returns:
      the name | 名称
    • getPriority

      default int getPriority()
      Gets the provider priority (higher value = higher priority). 获取提供者优先级(值越大优先级越高)。
      Returns:
      the priority | 优先级
    • isAvailable

      default boolean isAvailable()
      Checks if this provider is available. 检查此提供者是否可用。
      Returns:
      true if available | 如果可用则返回 true
    • load

      Map<String,Object> load(String yaml)
      Loads YAML string to Map. 将 YAML 字符串加载为 Map。
      Parameters:
      yaml - the YAML string | YAML 字符串
      Returns:
      the Map | Map
    • load

      <T> T load(String yaml, Class<T> clazz)
      Loads YAML string to object. 将 YAML 字符串加载为对象。
      Type Parameters:
      T - the type parameter | 类型参数
      Parameters:
      yaml - the YAML string | YAML 字符串
      clazz - the target type | 目标类型
      Returns:
      the object | 对象
    • load

      Map<String,Object> load(InputStream input)
      Loads YAML from input stream. 从输入流加载 YAML。
      Parameters:
      input - the input stream | 输入流
      Returns:
      the Map | Map
    • load

      <T> T load(InputStream input, Class<T> clazz)
      Loads YAML from input stream to object. 从输入流加载 YAML 为对象。
      Type Parameters:
      T - the type parameter | 类型参数
      Parameters:
      input - the input stream | 输入流
      clazz - the target type | 目标类型
      Returns:
      the object | 对象
    • loadAll

      List<Map<String,Object>> loadAll(String yaml)
      Loads multi-document YAML. 加载多文档 YAML。
      Parameters:
      yaml - the YAML string | YAML 字符串
      Returns:
      the list of documents | 文档列表
    • loadAll

      <T> List<T> loadAll(String yaml, Class<T> clazz)
      Loads multi-document YAML to objects. 加载多文档 YAML 为对象列表。
      Type Parameters:
      T - the type parameter | 类型参数
      Parameters:
      yaml - the YAML string | YAML 字符串
      clazz - the target type | 目标类型
      Returns:
      the list of objects | 对象列表
    • dump

      String dump(Object obj)
      Dumps object to YAML string. 将对象输出为 YAML 字符串。
      Parameters:
      obj - the object | 对象
      Returns:
      the YAML string | YAML 字符串
    • dump

      String dump(Object obj, YmlConfig config)
      Dumps object to YAML string with config. 使用配置将对象输出为 YAML 字符串。
      Parameters:
      obj - the object | 对象
      config - the configuration | 配置
      Returns:
      the YAML string | YAML 字符串
    • dump

      void dump(Object obj, OutputStream output)
      Dumps object to output stream. 将对象输出到输出流。
      Parameters:
      obj - the object | 对象
      output - the output stream | 输出流
    • dump

      void dump(Object obj, Writer writer)
      Dumps object to writer. 将对象输出到 Writer。
      Parameters:
      obj - the object | 对象
      writer - the writer | Writer
    • dumpAll

      String dumpAll(Iterable<?> documents)
      Dumps multiple documents to YAML string. 将多个文档输出为 YAML 字符串。
      Parameters:
      documents - the documents | 文档列表
      Returns:
      the YAML string | YAML 字符串
    • parseTree

      YmlNode parseTree(String yaml)
      Parses YAML to node tree. 将 YAML 解析为节点树。
      Parameters:
      yaml - the YAML string | YAML 字符串
      Returns:
      the root node | 根节点
    • parseTree

      YmlNode parseTree(InputStream input)
      Parses YAML from input stream to node tree. 从输入流将 YAML 解析为节点树。
      Parameters:
      input - the input stream | 输入流
      Returns:
      the root node | 根节点
    • isValid

      boolean isValid(String yaml)
      Checks if YAML string is valid. 检查 YAML 字符串是否有效。
      Parameters:
      yaml - the YAML string | YAML 字符串
      Returns:
      true if valid | 如果有效则返回 true
    • configure

      YmlProvider configure(YmlConfig config)
      Creates a configured provider instance. 创建配置后的提供者实例。
      Parameters:
      config - the configuration | 配置
      Returns:
      the configured provider | 配置后的提供者
    • getConfig

      YmlConfig getConfig()
      Gets the current configuration. 获取当前配置。
      Returns:
      the configuration | 配置