How does Jackson serialize and deserialize JSON in Spring Boot, and how do you customize it? स्प्रिंग बूट में Jackson JSON को कैसे सीरियलाइज़ और डीसीरियलाइज़ करता है, और इसे कैसे कस्टमाइज़ करें?
Spring Boot auto-configures Jackson's ObjectMapper as the default HTTP message converter, so any object returned from a @RestController method is automatically serialized to JSON, and any incoming JSON body annotated with @RequestBody is deserialized into a Java object using matching field names or getters/setters.
Customization is done with annotations like @JsonProperty to rename fields, @JsonIgnore to exclude a field, @JsonFormat for date formatting, or by defining a custom ObjectMapper bean to change global settings such as date serialization or null handling.
public class User {
@JsonProperty("full_name")
private String name;
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate createdAt;
@JsonIgnore
private String password;
}स्प्रिंग बूट डिफ़ॉल्ट HTTP मैसेज कन्वर्टर के रूप में Jackson के ObjectMapper को ऑटो-कॉन्फिगर करता है, इसलिए @RestController मेथड से रिटर्न किया गया कोई भी ऑब्जेक्ट अपने आप JSON में सीरियलाइज़ हो जाता है, और @RequestBody से एनोटेट कोई भी इनकमिंग JSON बॉडी Java ऑब्जेक्ट में डीसीरियलाइज़ हो जाती है।
कस्टमाइज़ेशन @JsonProperty, @JsonIgnore, @JsonFormat जैसे एनोटेशन से या ग्लोबल सेटिंग्स बदलने के लिए एक कस्टम ObjectMapper बीन डिफाइन करके किया जाता है।
public class User {
@JsonProperty("full_name")
private String name;
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate createdAt;
@JsonIgnore
private String password;
}Was this answer clear?