Annotation Interface XmlElement


XML Element Annotation - Maps a field to an XML element XML 元素注解 - 将字段映射到 XML 元素

This annotation specifies how a field should be mapped to an XML element.

此注解指定如何将字段映射到 XML 元素。

Features | 主要功能:

  • Map fields to XML elements - 将字段映射到 XML 元素
  • Custom element name and namespace - 自定义元素名称和命名空间
  • CDATA section support - CDATA 节支持
  • Default value and required field marking - 默认值和必需字段标记

Usage Examples | 使用示例:

@XmlRoot("user")
public class User {
    @XmlElement("name")
    private String name;

    @XmlElement(value = "description", cdata = true)
    private String description;

    @XmlElement(required = true)
    private String email;
}

Security | 安全性:

  • Thread-safe: Yes (annotation is immutable) - 线程安全: 是(注解不可变)
  • Null-safe: N/A (annotation type) - 空值安全: 不适用(注解类型)
Since:
JDK 25, opencode-base-xml V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Whether to use CDATA section.
    The default value.
    The namespace URI.
    boolean
    Whether the element is required.
    The element name.
  • Element Details

    • value

      String value
      The element name. 元素名称。
      Returns:
      the element name, defaults to field name | 元素名称,默认为字段名
      Default:
      ""
    • namespace

      String namespace
      The namespace URI. 命名空间 URI。
      Returns:
      the namespace URI | 命名空间 URI
      Default:
      ""
    • required

      boolean required
      Whether the element is required. 元素是否必需。
      Returns:
      true if required | 如果必需则返回 true
      Default:
      false
    • defaultValue

      String defaultValue
      The default value. 默认值。
      Returns:
      the default value | 默认值
      Default:
      ""
    • cdata

      boolean cdata
      Whether to use CDATA section. 是否使用 CDATA 节。
      Returns:
      true if CDATA | 如果使用 CDATA 则返回 true
      Default:
      false