Annotation Interface JsonPropertyOrder


@Target(TYPE) @Retention(RUNTIME) @Documented public @interface JsonPropertyOrder
JSON Property Order - Controls Property Serialization Order JSON 属性排序 - 控制属性序列化顺序

This annotation specifies the order in which properties are serialized. Properties listed in value() appear first in the specified order, followed by any remaining properties.

此注解指定属性序列化的顺序。value() 中列出的属性按指定顺序优先出现, 其余属性随后输出。

Example | 示例:

@JsonPropertyOrder(value = {"id", "name", "email"}, alphabetic = true)
public class User {
    private String email;
    private String name;
    private long id;
    private String phone;
}
// Serialized order: id, name, email, phone (remaining sorted alphabetically)

Features | 主要功能:

  • Explicit property ordering - 显式属性排序
  • Alphabetic sorting for remaining properties - 剩余属性按字母排序
  • Deterministic serialization output - 确定性的序列化输出

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 to sort remaining properties alphabetically.
    Ordered list of property names that define serialization order.
  • Element Details

    • value

      String[] value
      Ordered list of property names that define serialization order. 定义序列化顺序的属性名有序列表。

      Properties listed here appear first, in the specified order. Any remaining properties follow after.

      列出的属性按指定顺序优先出现,其余属性随后输出。

      Returns:
      the ordered property names - 有序属性名数组
      Default:
      {}
    • alphabetic

      boolean alphabetic
      Whether to sort remaining properties alphabetically. 是否按字母顺序排列剩余属性。

      If true, properties not listed in value() are sorted alphabetically. If false, they appear in their natural order.

      如果为true,未在 value() 中列出的属性按字母顺序排列。 如果为false,按其自然顺序出现。

      Returns:
      true to sort remaining properties alphabetically - 为true时按字母排序剩余属性
      Default:
      false