• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * instead of the usual method of collecting properties of value.
14  * Usually value will be of a simple scalar type
15  * (String or Number), but it can be any serializable type (Collection,
16  * Map or Bean).
17  *<p>
18  * At most one accessor of a <code>Class</code> can be annotated with this annotation;
19  * if more than one is found, an exception may be thrown.
20  * Also, if method signature of annotated method is not compatible with Getters,
21  * an exception may be thrown (whether exception is thrown or not is an
22  * implementation detail (due to filtering during introspection, some annotations
23  * may be skipped) and applications should not rely on specific behavior).
24  *<p>
25  * A typical usage is that of annotating <code>toString()</code>
26  * method so that returned String value is used as the JSON serialization;
27  * and if deserialization is needed, there is matching constructor
28  * or factory method annotated with {@link JsonCreator} annotation.
29  *<p>
30  * Boolean argument is only used so that sub-classes can "disable"
31  * annotation if necessary.
32  *<p>
33  * NOTE: when use for Java <code>enum</code>s, one additional feature is
34  * that value returned by annotated method is also considered to be the
35  * value to deserialize from, not just JSON String to serialize as.
36  * This is possible since set of Enum values is constant and it is possible
37  * to define mapping, but can not be done in general for POJO types; as such,
38  * this is not used for POJO deserialization.
39  *
40  * @see JsonCreator
41  */
42 @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD,
43     ElementType.FIELD // since 2.9
44 })
45 @Retention(RetentionPolicy.RUNTIME)
46 @JacksonAnnotation
47 public @interface JsonValue
48 {
49     /**
50      * Optional argument that defines whether this annotation is active
51      * or not. The only use for value 'false' if for overriding purposes.
52      * Overriding may be necessary when used
53      * with "mix-in annotations" (aka "annotation overrides").
54      * For most cases, however, default value of "true" is just fine
55      * and should be omitted.
56      */
value()57     boolean value() default true;
58 }
59