কম্পিউটার

জাভাতে জ্যাকসন ব্যবহার করে সিরিয়ালাইজেশনের সময় কীভাবে একটি ক্লাস উপেক্ষা করবেন?


দ্য জ্যাকসন @JsonIgnoreType টীকা a উপেক্ষা করতে ব্যবহার করা যেতে পারে শ্রেণী ক্রমিকীকরণের সময় প্রক্রিয়া এবং এটি সমস্ত বৈশিষ্ট্য চিহ্নিত করতে পারে অথবা ক্ষেত্র ক্রমিককরণের সময় উপেক্ষা করতে হবে এমন একটি শ্রেণির এবং ডিসারিয়ালাইজ করা একটি 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"
}

  1. কীভাবে জাভা ফাইল ক্লাস ব্যবহার করবেন

  2. জাভা হ্যাশম্যাপ ক্লাস কিভাবে ব্যবহার করবেন

  3. জাভাতে ডিফল্ট পদ্ধতি ব্যবহার করে হীরা সমস্যাটি কীভাবে সমাধান করবেন?

  4. জাভাতে জ্যাকসন লাইব্রেরি ব্যবহার করে নাল এবং খালি ক্ষেত্রগুলি কীভাবে উপেক্ষা করবেন?