The Jackson @JsonInclude annotation can be used to exclude properties or fields of a class under certain conditions, and It can be defined using the JsonInclude.Include enumeration. JsonInclude.Include enum Contains some constants, such as "ALWAYS", "NON_DEFAULT", "NON_EMPTY" and "NON_NULL", used to determine whether to exclude attributes (fields).
Syntax
public static enum JsonInclude.Include extends Enum<JSonInclude.Include>
Example
import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; import java.io.*; public class JsonIncludeTest { public static void main(String args[]) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); Employee emp = new Employee(); String jsonString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(emp); System.out.println(jsonString); } } // Employee class @JsonInclude(JsonInclude.Include.NON_EMPTY) class Employee { public int empId = 115; public String empName = null; @Override public String toString() { return "Employee{" + "empId=" + empId + ", empName='" + empName + '\'' + '}'; } }
Output
{ "empId" : 115 }
The above is the detailed content of What is the importance of Jackson @JsonInclude annotation in Java?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)