Annotation Interface YmlValue


@Retention(RUNTIME) @Target({FIELD,PARAMETER}) @Documented public @interface YmlValue
YAML Value Annotation - Binds YAML Path to Field YAML 值注解 - 将 YAML 路径绑定到字段

Specifies a YAML path to bind to a field. Supports nested path notation (e.g., "database.host") and default values.

指定要绑定到字段的 YAML 路径。支持嵌套路径表示法 (例如 "database.host")和默认值。

Features | 主要功能:

  • Bind nested YAML paths to fields using dot notation - 使用点号表示法将嵌套 YAML 路径绑定到字段
  • Default value fallback for missing properties - 缺失属性的默认值回退

Usage Example | 使用示例:

public class AppConfig {

    @YmlValue("server.port")
    private int port;

    @YmlValue(value = "server.host", defaultValue = "localhost")
    private String host;

    @YmlValue("database.connection-timeout")
    private Duration timeout;
}

// YAML content:
// server:
//   port: 8080
//   host: api.example.com
// database:
//   connection-timeout: 30s

AppConfig config = YmlBinder.bind(yaml, AppConfig.class);

Security | 安全性:

  • Thread-safe: Yes (annotation is inherently immutable) - 线程安全: 是(注解本身不可变)
  • Null-safe: N/A - 空值安全: 不适用
Since:
JDK 25, opencode-base-yml V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The YAML property path YAML 属性路径
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Default value if property is not found 属性未找到时的默认值
  • Element Details

    • value

      String value
      The YAML property path YAML 属性路径

      Supports dot notation for nested properties (e.g., "database.host").

      支持点表示法用于嵌套属性(例如 "database.host")。

      Returns:
      property path | 属性路径
    • defaultValue

      String defaultValue
      Default value if property is not found 属性未找到时的默认值

      Empty string means no default value.

      空字符串表示无默认值。

      Returns:
      default value | 默认值
      Default:
      ""