Annotation Interface JsonAnySetter


@Target({METHOD,FIELD}) @Retention(RUNTIME) @Documented public @interface JsonAnySetter
JSON Any Setter - Captures Unmatched JSON Properties JSON 任意设置器 - 捕获未匹配的 JSON 属性

This annotation marks a method (with two arguments: key and value) or a Map field to receive any JSON properties that do not map to a known Java field during deserialization.

此注解标记一个方法(两个参数:键和值)或一个 Map 字段, 用于在反序列化时接收任何未映射到已知 Java 字段的 JSON 属性。

Example | 示例:

public class ExtensibleConfig {
    private String name;

    @JsonAnySetter
    private Map<String, Object> extras = new LinkedHashMap<>();

    // or via method:
    @JsonAnySetter
    public void setExtra(String key, Object value) {
        extras.put(key, value);
    }
}

Features | 主要功能:

  • Captures all unmatched JSON properties - 捕获所有未匹配的 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-setter is enabled.
  • Element Details

    • enabled

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