Ignore fields in JSON using Jackson @JsonIgnoreProperties or @JsonIgnore

Jackson provides an efficient way to bind JSON to POJOs. However, at times, certain properties may need to be ignored while converting a JSON to Java Object or Java Object to JSON. Jackson provides three ways to Ignore fields in JSON.

  1. @JsonIgnoreProperties– This annotation can be used at the type level to ignore json properties. In the example below, we ignore the ‘tags’ property from the albums dataset.
  2. @JsonIgnore – This annotation can be set at the property level to ignore certain properties.
  3. Using Custom filters

The example below shows method 1 and 2. Also, note the use of the @JsonAutoDetect annotation.

Example for how to Ignore fields in JSON using Jackson

Databinding

The AlbumsFilter class

DatasetFilter class

3 thoughts on “Ignore fields in JSON using Jackson @JsonIgnoreProperties or @JsonIgnore

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.