Annotation Interface JsonEnumDefaultValue


@Target(FIELD) @Retention(RUNTIME) @Documented public @interface JsonEnumDefaultValue
JSON Enum Default Value - Marks Default Enum Constant for Unknown Values JSON 枚举默认值 - 标记未知值时的默认枚举常量

This marker annotation designates an enum constant as the fallback value when an unrecognized string is encountered during deserialization. At most one constant per enum type should carry this annotation.

此标记注解将一个枚举常量指定为在反序列化过程中遇到无法识别的字符串时的 回退值。每个枚举类型最多应有一个常量携带此注解。

Example | 示例:

public enum Color {
    RED,
    GREEN,
    BLUE,

    @JsonEnumDefaultValue
    UNKNOWN
}
// Deserializing "PURPLE" will yield Color.UNKNOWN instead of an error

Features | 主要功能:

  • Graceful handling of unknown enum values - 优雅处理未知枚举值
  • Marker annotation with no attributes - 无属性的标记注解
  • Applied to enum constants (fields) - 应用于枚举常量(字段)

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: