Javatpoint Logo
Javatpoint Logo

Property Inclusion Annotations in Jackson

Jackson provides more than one Property Inclusion annotation such as JsonIgnoreProperties, JsonIgnore, JsonIgnoreType, etc. These annotations are used for both serializing and deserialization. Each annotation is used in different use cases.

Property Inclusion Annotations in Jackson

Let's understand each one of them one by one with an example:

@JsonIgnoreProperties

@JsonIgnoreProperties annotation is an important property inclusion annotation that we mainly use for marking property or list of properties to be ignored. It is mainly used at the class level.

Let's take an example to understand how it works.

JsonIgnorePropertiesExample.java

Output:

Property Inclusion Annotations in Jackson

@JsonIgnore

@JsonIgnore annotation is another property inclusion annotation used for marking property or list of properties to be ignored. The only difference between @JsonIgnoreProperties and @JsonIgnore is that @JsonIgnore is used at field level, whereas @JsonIgnoreProperties is used as class level.

Let's take an example to understand how it works.

JsonIgnoreExample.java

Output:

Property Inclusion Annotations in Jackson

@JsonIgnoreType

@JsonIgnoreType is another annotation that we also used to mark a special type property to be ignored. Let's take the example of @JsonIgnoreType annotation to understand how it works.

JsonIgnoreTypeExample.java

Output:

Property Inclusion Annotations in Jackson

@JsonInclude

@JsonInclude is another important property inclusion annotation used to exclude properties with default, null or empty values. Let's take an example to understand how the annotation is used for excluding nulls from serialization.

JsonIncludeExample.java

Output:

Property Inclusion Annotations in Jackson

@JsonAutoDetect

@JsonAutoDetect is another important property inclusion annotation used to include properties that are not accessible otherwise. Let's understand how the annotation is used for including non-accessible properties.

JsonAutoDetectExample.java

Output:

Property Inclusion Annotations in Jackson





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA