Interface ConfigCodec<T>
- Type Parameters:
T- 目标类型
- All Known Implementing Classes:
BooleanCodec,IntegerCodec,ListCodec,StringCodec
public interface ConfigCodec<T>
配置值编解码器
为什么不用 Class<T>:Class<?> 对
List<String> / Map<String, Object> / Enum / Duration
这类类型很快就受限。用 codec 才能把"如何解析"与"如何写出"显式表达出来。
实现必须是无状态的:同一个 codec 实例会被所有 ConfigKey 共享。
- Since:
- 0.6.12
-
Method Summary
-
Method Details
-
read
把 YAML 原始值解析为目标类型- Parameters:
path- 配置路径(用于报错)raw- 原始值,可能为 null(字段存在但值为空)- Returns:
- 解析结果
- Throws:
ConfigValidationException- 类型不符或无法解析
-
write
把目标类型转成可写入 YAML 的原始值- Parameters:
value- 目标值- Returns:
- YAML 可写出的原始值
-
typeName
String typeName()类型名称,用于报错文案(如integer)- Returns:
- 类型名称
-
copy
复制值用于保证"默认值"不会在多个
Config实例之间共享同一个可变对象。 不可变类型直接返回原值。- Parameters:
value- 目标值- Returns:
- 副本
-