কম্পিউটার

কখন জাভাতে @JsonAutoDetect টীকা ব্যবহার করবেন?


The @JsonAutoDetect টীকা দৃশ্যমানতা ওভাররাইড করতে ক্লাস লেভেলে ব্যবহার করা যেতে পারে ক্রমিকীকরণের সময় একটি শ্রেণীর বৈশিষ্ট্য এবং ডিসিরিয়ালাইজেশন . আমরা "creatorVisibility এর মতো বৈশিষ্ট্যগুলির সাথে দৃশ্যমানতা সেট করতে পারি৷ ", "ক্ষেত্র দৃশ্যমানতা৷ ", "getterVisibility ", "সেটার ভিজিবিলিটি " এবং "isGetterVisibility৷ "। JsonAutoDetect ক্লাস পাবলিক স্ট্যাটিক ধ্রুবক সংজ্ঞায়িত করতে পারে যেগুলি জাভা ক্লাসের অনুরূপ দৃশ্যমানতার স্তর যেমন "যেকোনো", "DEFAULT", "NON_PRIVATE", "NONE", "PROTECTED_AND_PRIVATE" এবং "পাবলিক_শুধু৷ "।

উদাহরণ

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.*;
import java.io.*;
public class JsonAutoDetectTest {
   public static void main(String[] args) throws IOException {
      Address address = new Address("Madhapur", "Hyderabad", "Telangana");
      Name name = new Name("Raja", "Ramesh");
      Student student = new Student(address, name, true);
      ObjectMapper mapper = new ObjectMapper();
      String jsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(student);
      System.out.println("JSON: " + jsonString);
   }
}
// Address class
class Address {
   private String firstLine;
   private String secondLine;
   private String thirdLine;
   public Address(String firstLine, String secondLine, String thirdLine) {
      this.firstLine = firstLine;
      this.secondLine = secondLine;
      this.thirdLine = thirdLine;
   }
   public String getFirstLine() {
      return firstLine;
   }
   public String getSecondLine() {
      return secondLine;
   }
   public String getThirdLine() {
      return thirdLine;
   }
}
// Name class
class Name {
   private String firstName;
   private String secondName;
   public Name(String firstName, String secondName) {
      this.firstName = firstName;
      this.secondName = secondName;
   }
   public String getFirstName() {
      return firstName;
   }
   public String getSecondName() {
      return secondName;
   }
}
// Student class
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
class Student {
   private Address address;
   private Name name;
   private Boolean isActive;
   public Student(Address address, Name name, Boolean isActive) {
      this.address = address;
      this.name = name;
      this.isActive = isActive;
   }
}

আউটপুট

{
 "address" : {
    "firstLine" : "Madhapur",
    "secondLine" : "Hyderabad",
    "thirdLine" : "Telangana"
 },
 "name" : {
    "firstName" : "Raja",
    "secondName" : "Ramesh"
 },
 "isActive" : true
}

  1. আমরা কখন জাভাতে প্যাক() পদ্ধতি ব্যবহার করতে পারি?

  2. জাভাতে স্ট্রিংয়ের চেয়ে স্ট্রিংবাফার/স্ট্রিংবিল্ডার কোথায় ব্যবহার করবেন?

  3. কেন আমরা জাভাতে একটি স্ট্রিংয়ের পরিবর্তে একটি স্ট্রিংবাফার ব্যবহার করব?

  4. পাইথনে %s এর পরিবর্তে %r কখন ব্যবহার করবেন?