xref: /aosp_15_r20/external/jackson-annotations/src/main/java/com/fasterxml/jackson/annotation/JsonSubTypes.java (revision 2bf6642460ffb10303bd46207a4555f36d9e5945)
1 package com.fasterxml.jackson.annotation;
2 
3 import java.lang.annotation.ElementType;
4 import java.lang.annotation.Retention;
5 import java.lang.annotation.RetentionPolicy;
6 import java.lang.annotation.Target;
7 
8 /**
9  * Annotation used with {@link JsonTypeInfo} to indicate sub-types of serializable
10  * polymorphic types, and to associate logical names used within JSON content
11  * (which is more portable than using physical Java class names).
12  *<p>
13  * Note that just annotating a property or base type with this annotation does
14  * NOT enable polymorphic type handling: in addition, {@link JsonTypeInfo}
15  * or equivalent (such as enabling of so-called "default typing") annotation
16  * is needed, and only in such case is subtype information used.
17  */
18 @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.FIELD,
19     ElementType.METHOD, ElementType.PARAMETER})
20 @Retention(RetentionPolicy.RUNTIME)
21 @JacksonAnnotation
22 public @interface JsonSubTypes {
23     /**
24      * Subtypes of the annotated type (annotated class, or property value type
25      * associated with the annotated method). These will be checked recursively
26      * so that types can be defined by only including direct subtypes.
27      */
value()28     public Type[] value();
29 
30     /**
31      * Definition of a subtype, along with optional name(s). If no name is defined
32      * (empty Strings are ignored), class of the type will be checked for {@link JsonTypeName}
33      * annotation; and if that is also missing or empty, a default
34      * name will be constructed by type id mechanism.
35      * Default name is usually based on class name.
36      */
37     public @interface Type {
38         /**
39          * Class of the subtype
40          */
value()41         public Class<?> value();
42 
43         /**
44          * Logical type name used as the type identifier for the class, if defined; empty
45          * String means "not defined". Used unless {@link #names} is defined as non-empty.
46          */
name()47         public String name() default "";
48 
49         /**
50          * (optional) Logical type names used as the type identifier for the class: used if
51          * more than one type name should be associated with the same type.
52          *
53          * @since 2.12
54          */
names()55         public String[] names() default {};
56     }
57 }
58