Annotation Interface JsonProperty


@Target({FIELD,METHOD,PARAMETER}) @Retention(RUNTIME) @Documented public @interface JsonProperty
JSON Property - Defines JSON Field Mapping JSON 属性 - 定义 JSON 字段映射

This annotation maps a Java field to a JSON property name. It can be used on fields, getters, or setters.

此注解将 Java 字段映射到 JSON 属性名。可用于字段、getter 或 setter 方法。

Example | 示例:

public class User {
    @JsonProperty("user_name")
    private String userName;

    @JsonProperty(value = "email", required = true)
    private String email;

    @JsonProperty(access = Access.READ_ONLY)
    private LocalDateTime createdAt;
}

Features | 主要功能:

  • Custom JSON property name mapping - 自定义JSON属性名映射
  • Required field validation during deserialization - 反序列化时的必填字段验证
  • Access control (read-only, write-only) - 访问控制(只读、只写)

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:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Access type for property 属性的访问类型
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The access type for this property.
    The default value as a JSON literal if the property is absent.
    int
    Index for property ordering during serialization.
    boolean
    Whether this property is required during deserialization.
    The JSON property name.
  • Element Details

    • value

      String value
      The JSON property name. JSON 属性名。
      Returns:
      the property name, or empty for default field name - 属性名,空则使用默认字段名
      Default:
      ""
    • required

      boolean required
      Whether this property is required during deserialization. 反序列化时此属性是否必需。
      Returns:
      true if required - 如果必需则返回 true
      Default:
      false
    • defaultValue

      String defaultValue
      The default value as a JSON literal if the property is absent. 如果属性不存在时的默认值(JSON 字面量)。
      Returns:
      the default value - 默认值
      Default:
      ""
    • access

      The access type for this property. 此属性的访问类型。
      Returns:
      the access type - 访问类型
      Default:
      AUTO
    • index

      int index
      Index for property ordering during serialization. 序列化时属性排序的索引。
      Returns:
      the index (lower = first), or -1 for default order - 索引(越小越靠前),-1 表示默认顺序
      Default:
      -1