xref: /aosp_15_r20/external/jackson-databind/src/main/java/com/fasterxml/jackson/databind/annotation/JsonAppend.java (revision 0ed15c778abdfe0f5f51f6133673e1619d6e56e4)
1 package com.fasterxml.jackson.databind.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 import com.fasterxml.jackson.annotation.JsonInclude;
9 import com.fasterxml.jackson.databind.ser.VirtualBeanPropertyWriter;
10 
11 /**
12  * Annotation that may be used to add "virtual" properties to be written
13  * after regular properties (although ordering may be changed using
14  * both standard <code>@JsonPropertyOrder</code> annotation, and
15  * properties of this annotation).
16  *
17  * @since 2.5
18  */
19 @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE })
20 @Retention(RetentionPolicy.RUNTIME)
21 @com.fasterxml.jackson.annotation.JacksonAnnotation
22 public @interface JsonAppend
23 {
24     /**
25      * Set of attribute-backed properties to include when serializing
26      * a POJO.
27      */
attrs()28     public Attr[] attrs() default { };
29 
30     /**
31      * Set of general virtual properties to include when serializing a POJO.
32      */
props()33     public Prop[] props() default { };
34 
35     /**
36      * Indicator used to determine whether properties defined are to be
37      * appended after (false) or prepended before (true) regular properties.
38      * Affects all kinds of properties defined using this annotation.
39      */
prepend()40     public boolean prepend() default false;
41 
42     /**
43      * Definition of a single attribute-backed property.
44      * Attribute-backed properties will be appended after (or prepended before,
45      * as per {@link #prepend}) regular properties
46      * in specified order, although their placement may be further changed
47      * by the usual property-ordering functionality (alphabetic sorting;
48      * explicit ordering)
49      */
50     public @interface Attr
51     {
52         /**
53          * Name of attribute of which value to serialize. Is also used as the
54          * name of external property to write, unless overridden by
55          * assigning a value for {@link #propName()}.
56          */
value()57         public String value();
58 
59         /**
60          * Name to use for serializing value of the attribute; if not defined,
61          * {@link #value} will be used instead.
62          */
propName()63         public String propName() default "";
64 
65         /**
66          * Optional namespace to use; only relevant for data formats that use
67          * namespaces (like XML).
68          */
propNamespace()69         public String propNamespace() default "";
70 
71         /**
72          * When to include attribute-property. Default value indicates that
73          * property should only be written if specified attribute has a non-null
74          * value.
75          */
include()76         public JsonInclude.Include include() default JsonInclude.Include.NON_NULL;
77 
78         /**
79          * Metadata about property, similar to
80          * {@link com.fasterxml.jackson.annotation.JsonProperty#required()}.
81          */
required()82         public boolean required() default false;
83     }
84 
85     /**
86      * Definition of a single general virtual property.
87      */
88     public @interface Prop
89     {
90         /**
91          * Actual implementation class (a subtype of {@link VirtualBeanPropertyWriter})
92          * of the property to instantiate (using the no-argument default constructor).
93          */
value()94         public Class<? extends VirtualBeanPropertyWriter> value();
95 
96         /**
97          * Name of the property to possibly use for serializing (although implementation
98          * may choose to not use this information).
99          */
name()100         public String name() default "";
101 
102         /**
103          * Optional namespace to use along with {@link #name};
104          * only relevant for data formats that use namespaces (like XML).
105          */
namespace()106         public String namespace() default "";
107 
108         /**
109          * When to include  value of the property. Default value indicates that
110          * property should only be written if specified attribute has a non-null
111          * value. As with other properties, actual property implementation may or may
112          * not choose to use this inclusion information.
113          */
include()114         public JsonInclude.Include include() default JsonInclude.Include.NON_NULL;
115 
116         /**
117          * Metadata about property, similar to
118          * {@link com.fasterxml.jackson.annotation.JsonProperty#required()}.
119          */
required()120         public boolean required() default false;
121 
122         /**
123          * Nominal type of the property. Passed as type information for related
124          * virtual objects, and may (or may not be) used by implementation
125          * for choosing serializer to use.
126          */
type()127         public Class<?> type() default Object.class;
128     }
129 }
130