Annotation Interface JsonRootName


@Target(TYPE) @Retention(RUNTIME) @Documented public @interface JsonRootName
JSON Root Name - Specifies Root Wrapping Name JSON 根名称 - 指定根包装名称

This annotation specifies the root element name used to wrap the serialized JSON object. This is useful for APIs that expect a root wrapper element, or for XML interoperability.

此注解指定用于包装序列化 JSON 对象的根元素名称。对于期望根包装元素的 API 或 XML 互操作性非常有用。

Example | 示例:

@JsonRootName("user")
public class User {
    private String name;
    private int age;
}
// Serializes as: {"user":{"name":"Alice","age":30}}

@JsonRootName(value = "item", namespace = "http://example.com/ns")
public class Item {
    private String title;
}

Features | 主要功能:

  • Root wrapping for serialized output - 序列化输出的根包装
  • Optional namespace for XML interop - 可选的 XML 互操作命名空间

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
    Optional namespace for XML interoperability.
    The root wrapping name.
  • Element Details

    • value

      String value
      The root wrapping name. 根包装名称。
      Returns:
      the root name, or empty for default - 根名称,空则使用默认值
      Default:
      ""
    • namespace

      String namespace
      Optional namespace for XML interoperability. 可选的 XML 互操作命名空间。
      Returns:
      the namespace URI, or empty for none - 命名空间 URI,空则无命名空间
      Default:
      ""