Annotation Interface JsonAlias


@Target({FIELD,METHOD,PARAMETER}) @Retention(RUNTIME) @Documented public @interface JsonAlias
JSON Alias - Defines Alternative Deserialization Names JSON 别名 - 定义反序列化时的替代名称

This annotation defines one or more alternative names that are accepted during deserialization in addition to the primary property name. Aliases are only used for deserialization (reading); serialization always uses the primary name.

此注解定义一个或多个在反序列化时接受的替代名称,作为主属性名的补充。 别名仅用于反序列化(读取);序列化始终使用主名称。

Example | 示例:

public class User {
    @JsonAlias({"user_name", "username", "login"})
    private String name;

    @JsonAlias({"mail", "e-mail"})
    @JsonProperty("email")
    private String email;
}
// All of these JSON inputs map to "name":
// {"name":"Alice"}, {"user_name":"Alice"}, {"username":"Alice"}, {"login":"Alice"}

Features | 主要功能:

  • Multiple alternative names for deserialization - 反序列化时的多个替代名称
  • Works with JsonProperty for primary name - 与 JsonProperty 配合使用主名称
  • Supports fields, methods, and parameters - 支持字段、方法和参数

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:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The alternative names accepted during deserialization.
  • Element Details

    • value

      String[] value
      The alternative names accepted during deserialization. 反序列化时接受的替代名称。
      Returns:
      the array of alias names - 别名数组