Annotation Interface JsonUnwrapped


@Target({FIELD,METHOD}) @Retention(RUNTIME) @Documented public @interface JsonUnwrapped
JSON Unwrapped - Unwraps Nested Object Properties JSON 展开 - 展开嵌套对象属性

This annotation indicates that a nested object's properties should be serialized as if they belong to the parent object, effectively "unwrapping" the nested structure. During deserialization, the flat properties are "wrapped" back into the nested object.

此注解表示嵌套对象的属性应序列化为父对象的属性, 有效地"展开"嵌套结构。反序列化时,扁平属性将被 "包装"回嵌套对象。

Example | 示例:

public class Order {
    private String orderId;

    @JsonUnwrapped
    private Address shippingAddress;

    @JsonUnwrapped(prefix = "billing_")
    private Address billingAddress;
}

public class Address {
    private String street;
    private String city;
}

// Without @JsonUnwrapped:
// {"orderId":"1", "shippingAddress":{"street":"...", "city":"..."}}

// With @JsonUnwrapped:
// {"orderId":"1", "street":"...", "city":"...", "billing_street":"...", "billing_city":"..."}

Features | 主要功能:

  • Flatten nested object properties into parent - 将嵌套对象属性展开到父级
  • Prefix support to avoid name conflicts - 前缀支持以避免名称冲突
  • Suffix support for additional naming control - 后缀支持以进行额外的命名控制
  • 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 unwrapping is enabled.
    Prefix to prepend to unwrapped property names.
    Suffix to append to unwrapped property names.
  • Element Details

    • enabled

      boolean enabled
      Whether unwrapping is enabled. 是否启用展开。

      Can be set to false to programmatically disable unwrapping.

      可设置为 false 以编程方式禁用展开。

      Returns:
      true if unwrapping is enabled (default) - 如果启用展开则返回 true(默认)
      Default:
      true
    • prefix

      String prefix
      Prefix to prepend to unwrapped property names. 添加到展开属性名前的前缀。

      Useful for avoiding name conflicts when multiple objects are unwrapped into the same parent.

      在多个对象展开到同一父级时,用于避免名称冲突。

      Returns:
      the prefix, or empty string for no prefix - 前缀,空字符串表示无前缀
      Default:
      ""
    • suffix

      String suffix
      Suffix to append to unwrapped property names. 添加到展开属性名后的后缀。
      Returns:
      the suffix, or empty string for no suffix - 后缀,空字符串表示无后缀
      Default:
      ""