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 that indicates that the logical property that
10  * the accessor (field, getter/setter method or Creator parameter
11  * [of {@link JsonCreator}-annotated constructor or factory method])
12  * is to be ignored by introspection-based
13  * serialization and deserialization functionality.
14  *<p>
15  * Annotation only needs to be added to one of the accessors (often
16  * getter method, but may be setter, field or creator parameter),
17  * if the complete removal of the property is desired.
18  * However: if only particular accessor is to be ignored (for example,
19  * when ignoring one of potentially conflicting setter methods),
20  * this can be done by annotating other not-to-be-ignored accessors
21  * with {@link JsonProperty} (or its equivalents). This is considered
22  * so-called "split property" case and allows definitions of
23  * "read-only" (read from input into POJO) and "write-only" (write
24  * in output but ignore on output)
25  *<br>
26  * NOTE! As Jackson 2.6, there is a new and improved way to define
27  * `read-only` and `write-only` properties, using
28  * {@link JsonProperty#access()} annotation: this is recommended over
29  * use of separate <code>JsonIgnore</code> and {@link JsonProperty}
30  * annotations.
31  *<p>
32  * For example, a "getter" method that would otherwise denote
33  * a property (like, say, "getValue" to suggest property "value")
34  * to serialize, would be ignored and no such property would
35  * be output unless another annotation defines alternative method to use.
36  *<p>
37  * When ignoring the whole property, the default behavior if encountering
38  * such property in input is to ignore it without exception; but if there
39  * is a {@link JsonAnySetter} it will be called instead. Either way,
40  * no exception will be thrown.
41  *<p>
42  * Annotation is usually used just a like a marker annotation, that
43  * is, without explicitly defining 'value' argument (which defaults
44  * to <code>true</code>): but argument can be explicitly defined.
45  * This can be done to override an existing `JsonIgnore` by explicitly
46  * defining one with 'false' argument: either in a sub-class, or by
47  * using "mix-in annotations".
48  */
49 @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD})
50 @Retention(RetentionPolicy.RUNTIME)
51 @JacksonAnnotation
52 public @interface JsonIgnore
53 {
54     /**
55      * Optional argument that defines whether this annotation is active
56      * or not. The only use for value 'false' if for overriding purposes
57      * (which is not needed often); most likely it is needed for use
58      * with "mix-in annotations" (aka "annotation overrides").
59      * For most cases, however, default value of "true" is just fine
60      * and should be omitted.
61      *
62      * @return True if annotation is enabled (normal case); false if it is to
63      *   be ignored (only useful for mix-in annotations to "mask" annotation)
64      */
value()65     boolean value() default true;
66 }
67