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 Summary
Modifier and TypeMethodDescriptionCreates a configured provider instance.Dumps object to YAML string.Dumps object to YAML string with config.voiddump(Object obj, OutputStream output) Dumps object to output stream.voidDumps object to writer.Dumps multiple documents to YAML string.Gets the current configuration.getName()Gets the provider name.default intGets the provider priority (higher value = higher priority).default booleanChecks if this provider is available.booleanChecks if YAML string is valid.load(InputStream input) Loads YAML from input stream.<T> Tload(InputStream input, Class<T> clazz) Loads YAML from input stream to object.Loads YAML string to Map.<T> TLoads YAML string to object.Loads multi-document YAML.<T> List<T> Loads multi-document YAML to objects.parseTree(InputStream input) Parses YAML from input stream to node tree.Parses YAML to node tree.
-
Method Details
-
getName
-
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
-
load
-
load
Loads YAML from input stream. 从输入流加载 YAML。- Parameters:
input- the input stream | 输入流- Returns:
- the Map | Map
-
load
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
-
loadAll
-
dump
-
dump
-
dump
Dumps object to output stream. 将对象输出到输出流。- Parameters:
obj- the object | 对象output- the output stream | 输出流
-
dump
-
dumpAll
-
parseTree
-
parseTree
Parses YAML from input stream to node tree. 从输入流将 YAML 解析为节点树。- Parameters:
input- the input stream | 输入流- Returns:
- the root node | 根节点
-
isValid
Checks if YAML string is valid. 检查 YAML 字符串是否有效。- Parameters:
yaml- the YAML string | YAML 字符串- Returns:
- true if valid | 如果有效则返回 true
-
configure
Creates a configured provider instance. 创建配置后的提供者实例。- Parameters:
config- the configuration | 配置- Returns:
- the configured provider | 配置后的提供者
-
getConfig
-