Jackson @JsonIgnoreType एनोटेशन का उपयोग सीरियलाइज़ेशन प्रक्रिया के दौरान क्लास को अनदेखा करने के लिए किया जा सकता है और यह क्लास के सभी गुणों या फ़ील्ड्स को JSON ऑब्जेक्ट को सीरियलाइज़ और डिसीरियलाइज़ करते समय अनदेखा करने के लिए चिह्नित कर सकता है।
सिंटैक्स
@Target(value={ANNOTATION_TYPE,TYPE}) @Retention(value=RUNTIME) public @interface JsonIgnoreType उदाहरण
import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; import java.io.*; public class JsonIgnoreTypeTest { public static void main(String args[]) throws IOException { Employee emp = new Employee(); ObjectMapper mapper = new ObjectMapper(); String jsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(emp); System.out.println(jsonString); } } // Employee class class Employee { @JsonIgnoreType public static class Address { public String firstLine = null; public String secondLine= null; public String thirdLine = null; @Override public String toString() { return "Address{" + "firstLine='" + firstLine+ '\'' + ", secondLine='" + secondLine+ '\'' + ", thirdLine='" + thirdLine + '\'' + '}'; } } // end of Address class public long empId = 115; public String empName = "Raja Ramesh"; public Address empAddress = new Address(); @Override public String toString() { return "Employee{" + "empId=" + empId + ", empName='" + empName + '\'' + ", empAddress=" + empAddress + '}'; } } आउटपुट
{ "empId" : 115, "empName" : "Raja Ramesh" }