Annotation Interface JsonAnyGetter


@Target({METHOD,FIELD}) @Retention(RUNTIME) @Documented public @interface JsonAnyGetter
JSON Any Getter - Serializes Map Entries as Regular Properties JSON 任意获取器 - 将 Map 条目序列化为普通属性

This annotation marks a no-argument method returning a Map or a Map field whose entries are serialized as regular JSON properties alongside other declared properties.

此注解标记一个无参方法(返回 Map)或一个 Map 字段,其条目将与其他声明的属性一起序列化为普通 JSON 属性。

Example | 示例:

public class ExtensibleConfig {
    private String name;
    private Map<String, Object> extras = new LinkedHashMap<>();

    @JsonAnyGetter
    public Map<String, Object> getExtras() {
        return extras;
    }
}
// Serializes as: {"name":"...", "key1":"val1", "key2":"val2"}

Features | 主要功能:

  • Flattens Map entries into the parent JSON object - 将 Map 条目展平到父 JSON 对象中
  • Supports both method and Map field targets - 支持方法和 Map 字段目标
  • Can be disabled via enabled = false - 可通过 enabled = false 禁用

Security | 安全性:

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

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Whether this any-getter is enabled.
  • Element Details

    • enabled

      boolean enabled
      Whether this any-getter is enabled. 此任意获取器是否启用。
      Returns:
      true if enabled - 如果启用则返回 true
      Default:
      true