Annotation Interface JsonSubTypes
JSON Sub Types - Known Subtypes for Polymorphic Deserialization
JSON 子类型 - 多态反序列化的已知子类型
This annotation lists known subtypes of a polymorphic base type, enabling
the JSON framework to resolve concrete implementations during deserialization.
It is typically used in conjunction with JsonTypeInfo.
此注解列出多态基类型的已知子类型,使 JSON 框架能够在反序列化期间
解析具体实现。通常与 JsonTypeInfo 一起使用。
Example | 示例:
@JsonTypeInfo(id = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(value = Circle.class, name = "circle"),
@JsonSubTypes.Type(value = Rectangle.class, name = "rectangle"),
@JsonSubTypes.Type(value = Triangle.class, name = "triangle", names = {"tri", "三角形"})
})
public abstract class Shape {
public abstract double area();
}
Features | 主要功能:
- Declare known subtypes for polymorphic deserialization - 声明多态反序列化的已知子类型
- Map logical names to concrete implementations - 将逻辑名映射到具体实现
- Support alternative name aliases for subtypes - 支持子类型的别名
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 ClassesModifier and TypeClassDescriptionstatic @interfaceKnown Subtype Declaration 已知子类型声明 -
Required Element Summary
Required Elements
-
Element Details
-
value
JsonSubTypes.Type[] valueThe known subtypes. 已知的子类型。- Returns:
- array of known subtype declarations - 已知子类型声明的数组
-