Annotation Interface JsonCreator


@Target({CONSTRUCTOR,METHOD}) @Retention(RUNTIME) @Documented public @interface JsonCreator
JSON Creator - Marks a Constructor or Factory Method for Deserialization JSON 创建器 - 标记用于反序列化的构造函数或工厂方法

This annotation indicates that the annotated constructor or static factory method should be used to create instances during JSON deserialization.

此注解表示被标注的构造函数或静态工厂方法应在 JSON 反序列化时用于创建实例。

Example | 示例:

public class User {
    private final String name;
    private final int age;

    @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
    public User(@JsonProperty("name") String name,
                @JsonProperty("age") int age) {
        this.name = name;
        this.age = age;
    }

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static User fromString(String value) {
        return new User(value, 0);
    }
}

Features | 主要功能:

  • Constructor-based deserialization - 基于构造函数的反序列化
  • Factory method deserialization - 工厂方法反序列化
  • Delegating mode for single-value types - 委托模式用于单值类型
  • Properties mode for multi-argument constructors - 属性模式用于多参数构造函数

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 
    Creator mode that defines how arguments are bound.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The creator mode to use.