-
-
Notifications
You must be signed in to change notification settings - Fork 334
Jackson Annotations
Tatu Saloranta edited this page Nov 19, 2013
·
18 revisions
This page lists all general-purpose Jackson 2.0 annotations, grouped by functionality.
For older (Jackson 1.x) annotations, refer to FasterXML Wiki.
All annotations include a brief explanation, and (in near future!) a link to full explanation with basic usage examples.
NOTE: Contributions welcome!!!
- @JsonProperty (also indicates that property is to be included) is used to indicate external property name, name used in data format (JSON or one of other supported data formats)
- @JsonAutoDetect: class annotation used for overriding property introspection definitions
- @JsonIgnore: simple annotation to use for ignoring specified properties
- @JsonIgnoreProperties: per-class annotation to list properties to ignore, or to indicate that any unknown properties are to be ignored.
- On serialization,
@JsonIgnoreProperties({"prop1", "prop2"})
ignores listed properties - On deserialization,
@JsonIgnoreProperties(ignoreUnknown=true)
ignores properties that don't have getter/setters
- On serialization,
- @JsonIgnoreType: per-class annotation to indicate that all properties of annotated type are to be ignored.
- @JsonInclude: annotation used to define if certain "non-values" (nulls or empty values) should not be included when serializing; can be used on per-property basis as well as default for a class (to be used for all properties of a class)
- @JsonFormat: general annotation that has per-type behavior; can be used for example to specify format to use when serializing Date/Time values.
- @JsonUnwrapped: property annotation used to define that value should be "unwrapped" when serialized (and wrapped again when deserializing), resulting in flattening of data structure, compared to POJO structure.
- @JsonView: property annotation used for defining View(s) in which property will be included for serialization, deserialization.
- @JacksonInject: annotation to indicate that property should get its value via "injection", and not from data (JSON).
- @JsonAnySetter: annotation used for defining a two-argument method as "any setter", used for deserializing values of otherwise unmapped JSON properties
- @JsonCreator: annotation used for indicating that a constructor or static factory method should be used for creating value instances during deserialization.
- @JsonSetter: alternative to @JsonProperty, for marking that specified method is a "setter-method"
- @JsonAnyGetter: annotation used to define a getter as "any getter", which returns a
java.util.Map
, contents of which will be serialized as additional properties for JSON Object, along with regular properties that the Object may have. - @JsonGetter: alternative to @JsonProperty, for marking that specified method is a "getter-method"
- @JsonPropertyOrder: annotation for specifying order in which properties are serialized
- @JsonRawValue: per-property marker that can be used to specify that the value of property is to be included in serialization ''exactly'' as is, with no escaping or decoration -- useful for embedding pre-serialized JSON (or whatever data format is being used) in output
- @JsonValue: per-property marker to indicate that the POJO should serialization is to be done using value of the property, often a
java.lang.String
(like annotationtoString()
method) - @JsonRootName: class annotation used to indicate name of "wrapper" entry used for root value, if root-wrapping is enabled
- @JsonSubTypes: class annotation used to indicate sub-types of annotated type; necessary when deserializing polymorphic types using logical type names (and not class names)
- @JsonTypeId: property annotation used to indicate that the property value should be used as the
Type Id
for object, instead of using class name or external type name. - @JsonTypeInfo: class/property annotation used to indicate details of what type information is included in serialization, as well as how.
- @JsonTypeName: class annotation used to define logical type name to use for annotated class; type name can be used as
Type Id
(depending on settings of@JsonTypeInfo
)
- @JsonManagedReference, @JsonBackReference: pair of annotations used to indicate and handle parent/child relationships expressed with pair of matching properties
- @JsonIdentityInfo: class/property annotation used to indicate that
Object Identity
is to be used when serializing/deserializing values, such that multiple references to a single Java Object can be properly deserialized. This can used to properly deal with cyclic object graphs and directed-acyclic graphs.
This group includes annotations used on other annotations.
- @JacksonAnnotation: marker annotation added to all Jackson-defined annotations (which includes all other annotations contained in this package)
- @JacksonAnnotationsInside: marked annotation used to indicate that a custom annotation contains Jackson annotations; used to allow "annotation bundles", custom annotations that are annotated with Jackson annotations (why? to allow adding just a single annotation to represent set of multiple Jackson annotations)
It is also possible to use JAXB annotations in addition to or instead of these core annotations.