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 that can be used to define ordering (possibly partial) to use
10  * when serializing object properties. Properties included in annotation
11  * declaration will be serialized first (in defined order), followed by
12  * any properties not included in the definition.
13  * Annotation definition will override any implicit orderings (such as
14  * guarantee that Creator-properties are serialized before non-creator
15  * properties)
16  *<p>
17  * Examples:
18  *<pre>
19  *  // ensure that "id" and "name" are output before other properties
20  *  &#64;JsonPropertyOrder({ "id", "name" })
21  *  // order any properties that don't have explicit setting using alphabetic order
22  *  &#64;JsonPropertyOrder(alphabetic=true)
23  *</pre>
24  *<p>
25  * This annotation may or may not have effect on deserialization: for basic JSON
26  * handling there is no effect, but for other supported data types (or structural
27  * conventions) there may be.
28  *<p>
29  * NOTE: annotation is allowed for properties, starting with 2.4, mostly to support
30  * alphabetic ordering of {@link java.util.Map} entries.
31  */
32 @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE,
33     ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD})
34 @Retention(RetentionPolicy.RUNTIME)
35 @JacksonAnnotation
36 public @interface JsonPropertyOrder
37 {
38     /**
39      * Order in which properties of annotated object are to be serialized in.
40      */
value()41     public String[] value() default { };
42 
43     /**
44      * Property that defines what to do regarding ordering of properties
45      * not explicitly included in annotation instance. If set to true,
46      * they will be alphabetically ordered; if false, order is
47      * undefined (default setting)
48      */
alphabetic()49     public boolean alphabetic() default false;
50 }
51