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
+ * Marker annotation
10
+ * that indicates that the value of annotated accessor (either field
11
+ * or "getter" method [a method with non-void return type, no args])
12
+ * is to be used as the single value to serialize for the instance.
13
+ * This value will be used only if the instance is being serialized
14
+ * as a key in a Map type.
15
+ * Usually value will be of a simple scalar type
16
+ * (String or Number), but it can be any serializable type (Collection,
17
+ * Map or Bean).
18
+ *<p>
19
+ * At most one accessor of a <code>Class</code> can be annotated with this annotation;
20
+ * if more than one is found, an exception may be thrown.
21
+ * Also, if method signature of annotated method is not compatible with Getters,
22
+ * an exception may be thrown (whether exception is thrown or not is an
23
+ * implementation detail (due to filtering during introspection, some annotations
24
+ * may be skipped) and applications should not rely on specific behavior).
25
+ *<p>
26
+ * A typical usage is that of annotating <code>toString()</code>
27
+ * method so that returned String value is used as the JSON serialization;
28
+ * and if deserialization is needed, there is matching constructor
29
+ * or factory method annotated with {@link JsonCreator} annotation.
30
+ *<p>
31
+ * Boolean argument is only used so that sub-classes can "disable"
32
+ * annotation if necessary.
33
+ *
34
+ * @see JsonValue
35
+ */
36
+ @ Target ({ElementType .ANNOTATION_TYPE , ElementType .METHOD ,
37
+ ElementType .FIELD
38
+ })
39
+ @ Retention (RetentionPolicy .RUNTIME )
40
+ @ JacksonAnnotation
41
+ public @interface JsonKey
42
+ {
43
+ /**
44
+ * Optional argument that defines whether this annotation is active
45
+ * or not. The only use for value 'false' if for overriding purposes.
46
+ * Overriding may be necessary when used
47
+ * with "mix-in annotations" (aka "annotation overrides").
48
+ * For most cases, however, default value of "true" is just fine
49
+ * and should be omitted.
50
+ */
51
+ boolean value () default true ;
52
+ }
0 commit comments