Jackson Annotations

Some of the most commonly used Jackson annotation.

Table of contents

No heading

No headings in the article.

AnnotationPurposeUsage
@JsonAnyGetterEnables the flexibility of using a Map field as standard properties.Use when you want to serialize a Map's key-value pairs as JSON properties.
@JsonGetterMarks a method as a getter for a specific property, alternative to @JsonProperty.Useful when the method name doesn't follow JavaBean naming conventions or for custom serialization.
@JsonPropertyOrderSpecifies the serialization order of JSON properties.Apply when you need a custom order in your serialized JSON, different from the default alphabetical order.
@JsonRawValueInstructs Jackson to serialize a property exactly as it is.Good for embedding custom JSON or pre-serialized JSON content.
@JsonValueIndicates a single method to use for serializing the entire instance.Useful for serializing a complex object through a single method, often used with enums.
@JsonRootNameSpecifies the name of the root wrapper if wrapping is enabled.Use when you need to wrap the JSON output in a root element with a custom name.
@JsonSerializeIndicates a custom serializer to use for a property or class.Implement when you need custom serialization logic, different from the default Jackson provides.
@JsonCreatorMarks a constructor or factory method for use in deserialization.Helpful when the JSON structure doesn't match the Java object structure directly.
@JacksonInjectIndicates that a property value will be obtained from the injection, not JSON.Use for properties that need to be injected, not read from the JSON.
@JsonAnySetterAllows for the flexibility of adding unknown properties to a Map.Apply when you want to handle additional, undeclared properties in JSON.
@JsonSetterMarks a method as a setter for a specific property, alternative to @JsonProperty.Useful for custom deserialization logic or when method names do not follow JavaBean naming conventions.
@JsonDeserializeIndicates the use of a custom deserializer.Use when custom deserialization logic is needed.
@JsonAliasDefines one or more alternative names for a property during deserialization.Apply when a JSON property may have multiple aliases.