<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: abharan gupta</title>
    <description>The latest articles on DEV Community by abharan gupta (@abharangupta).</description>
    <link>https://dev.to/abharangupta</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2250964%2Fb8d9fe03-68a0-4d56-9e0c-9fef32caf0ee.jpg</url>
      <title>DEV Community: abharan gupta</title>
      <link>https://dev.to/abharangupta</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abharangupta"/>
    <language>en</language>
    <item>
      <title>Kafka 4.0 Unleashed: How to Upgrade and Thrive in a ZooKeeper-Free World</title>
      <dc:creator>abharan gupta</dc:creator>
      <pubDate>Mon, 21 Apr 2025 08:24:23 +0000</pubDate>
      <link>https://dev.to/abharangupta/kafka-40-unleashed-how-to-upgrade-and-thrive-in-a-zookeeper-free-world-2148</link>
      <guid>https://dev.to/abharangupta/kafka-40-unleashed-how-to-upgrade-and-thrive-in-a-zookeeper-free-world-2148</guid>
      <description>&lt;h2&gt;
  
  
  Understanding the Differences Between Older Kafka Versions and Kafka 4.0 — And How to Upgrade Smoothly
&lt;/h2&gt;

&lt;p&gt;Apache Kafka has been a game-changer in the world of real-time data streaming for years. But with the release of Kafka 4.0, there are some big changes that everyone should know about—especially if you’re running older versions. Whether you’re a developer, a DevOps engineer, or a tech enthusiast, this blog will break down what’s new, what’s gone, and how to prepare your Kafka cluster for the upgrade.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What’s New in Kafka 4.0? The Big Picture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kafka 4.0 isn’t just another update; it’s a major milestone. The biggest headline is that Kafka no longer uses ZooKeeper for managing cluster metadata and coordination. This is a huge architectural change that simplifies Kafka’s operation but also means the upgrade path requires some planning.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s walk through the main differences between older Kafka versions (like 2.x or 3.x) and Kafka 4.0 in simple terms.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Goodbye ZooKeeper, Hello KRaft!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Older Versions:&lt;/strong&gt;&lt;br&gt;
Kafka used ZooKeeper as a separate system to keep track of cluster metadata — things like which brokers are alive, topic configurations, and partition leadership. This meant you had to run and manage a ZooKeeper ensemble alongside your Kafka brokers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kafka 4.0:&lt;/strong&gt;&lt;br&gt;
ZooKeeper is completely removed. Kafka now uses a built-in consensus system called KRaft (Kafka Raft Metadata mode) to handle all metadata internally. This means fewer moving parts, easier setup, and faster cluster management.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;&lt;br&gt;
No more ZooKeeper means less complexity and fewer components to maintain. But it also means you can’t just upgrade Kafka and keep ZooKeeper running—you need to migrate your cluster metadata to KRaft first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Smarter Consumer Rebalancing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Older Versions:&lt;/strong&gt;&lt;br&gt;
When Kafka consumers (applications that read data) join or leave a group, Kafka pauses message consumption during rebalancing. This could cause noticeable delays or downtime, especially in large clusters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kafka 4.0:&lt;/strong&gt;&lt;br&gt;
Introduces a new consumer group protocol (called KIP-848) that makes rebalancing faster and less disruptive. Consumers can continue processing most partitions even while the group is rebalancing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;&lt;br&gt;
Your streaming applications will experience fewer interruptions and better performance during scaling or recovery events.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Updated Java Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Older Versions:&lt;/strong&gt;&lt;br&gt;
Kafka brokers and clients supported Java 8 and Java 11, which were the industry standards for many years.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kafka 4.0:&lt;/strong&gt;&lt;br&gt;
Requires Java 17 for brokers, Connect, and tools, and Java 11 for clients and Kafka Streams applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;&lt;br&gt;
You’ll need to upgrade your Java runtime environments before moving to Kafka 4.0. This may require coordination with your infrastructure or development teams.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. MirrorMaker 1 Is Gone&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Older Versions:&lt;/strong&gt;&lt;br&gt;
MirrorMaker 1 was a basic tool for replicating data between Kafka clusters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kafka 4.0:&lt;/strong&gt;&lt;br&gt;
MirrorMaker 1 has been removed. Only MirrorMaker 2 remains, which is more robust, scalable, and easier to manage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;&lt;br&gt;
If you’re still using MirrorMaker 1, you’ll need to migrate to MirrorMaker 2 before upgrading.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Logging Changes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Older Versions:&lt;/strong&gt;&lt;br&gt;
Kafka used Log4j for logging.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kafka 4.0:&lt;/strong&gt;&lt;br&gt;
Kafka has fully switched to Log4j2, which is more secure and modern.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;&lt;br&gt;
You may need to update your logging configurations and tools.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. API Clean-Up&lt;/strong&gt;&lt;br&gt;
Kafka 4.0 removes APIs that have been deprecated for over a year. This helps keep the codebase clean and encourages users to adopt the latest, supported features.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Early Access to Queues for Kafka&lt;/strong&gt;&lt;br&gt;
Kafka traditionally uses a publish-subscribe messaging model. Kafka 4.0 introduces early access to queue semantics (via KIP-932), enabling point-to-point messaging patterns.&lt;/p&gt;

&lt;p&gt;This is exciting for use cases that require strict message ordering and processing guarantees.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Upgrade to Kafka 4.0: A Step-by-Step Guide
&lt;/h2&gt;

&lt;p&gt;Upgrading to Kafka 4.0 isn’t as simple as flipping a switch—especially because of the ZooKeeper removal. Here’s a clear, step-by-step approach to make your upgrade smooth and safe.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Check Your Current Setup and Prepare&lt;br&gt;
Know your Kafka version: If you’re running anything older than 3.9.x, you’ll first need to upgrade to 3.9.x before moving to 4.0.&lt;/p&gt;

&lt;p&gt;Check Java versions: Make sure your brokers and clients can run on the required Java versions (Java 17 for brokers, Java 11 for clients).&lt;/p&gt;

&lt;p&gt;Backup everything: Always back up your Kafka data, configurations, and metadata before starting the upgrade.&lt;/p&gt;

&lt;p&gt;Test in a staging environment: Don’t upgrade your production cluster first. Run tests on a staging or dev cluster.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Upgrade to Kafka 3.9.x (The Bridge Version)&lt;br&gt;
Kafka 3.9.x supports both ZooKeeper and KRaft modes and includes tools to migrate metadata from ZooKeeper to KRaft.&lt;/p&gt;

&lt;p&gt;Upgrade your brokers to 3.9.x.&lt;/p&gt;

&lt;p&gt;Make sure everything is stable and running as expected.&lt;/p&gt;

&lt;p&gt;Start planning your migration to KRaft.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Migrate from ZooKeeper to KRaft&lt;br&gt;
This is the most critical step.&lt;/p&gt;

&lt;p&gt;Use Kafka’s official migration tools and follow the detailed migration guide.&lt;/p&gt;

&lt;p&gt;The migration process moves all cluster metadata from ZooKeeper into Kafka’s internal KRaft quorum.&lt;/p&gt;

&lt;p&gt;Validate that your cluster is healthy and all topics, partitions, and configurations are intact after migration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Upgrade to Kafka 4.0&lt;br&gt;
Once your cluster is running in KRaft mode on 3.9.x:&lt;/p&gt;

&lt;p&gt;Upgrade your brokers to Kafka 4.0.&lt;/p&gt;

&lt;p&gt;Upgrade clients and tools, making sure they’re compatible with Kafka 4.0 and the new Java versions.&lt;/p&gt;

&lt;p&gt;Monitor your cluster closely for any issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Post-Upgrade Cleanup and Optimization&lt;br&gt;
Remove any deprecated APIs or features.&lt;/p&gt;

&lt;p&gt;Switch from MirrorMaker 1 to MirrorMaker 2 if you haven’t already.&lt;/p&gt;

&lt;p&gt;Update your logging configurations to use Log4j2.&lt;/p&gt;

&lt;p&gt;Explore new features like improved consumer rebalancing and queue semantics.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Kafka 4.0 is a powerful, modernized release that simplifies cluster management and boosts performance. But because it removes ZooKeeper and updates core dependencies, it requires a thoughtful upgrade plan.&lt;/p&gt;

&lt;p&gt;By following the steps above—starting with upgrading to Kafka 3.9.x, migrating to KRaft, and then moving to Kafka 4.0—you’ll ensure a smooth transition with minimal downtime.&lt;/p&gt;

&lt;p&gt;If you’re running Kafka in production, don’t rush the upgrade. Test thoroughly, involve your teams, and take advantage of Kafka’s detailed documentation and tools.&lt;/p&gt;

&lt;p&gt;Kafka 4.0 is the future of streaming platforms—embrace it to unlock new possibilities and keep your data pipelines running smoothly!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Have you started your Kafka 4.0 upgrade? Feel free to share your experiences or ask questions in the comments below!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>kafka</category>
      <category>springboot</category>
      <category>programming</category>
    </item>
    <item>
      <title>Dive into Jackson for JSON in Java: Understanding JsonNode, ArrayNode, and ObjectMapper</title>
      <dc:creator>abharan gupta</dc:creator>
      <pubDate>Tue, 22 Oct 2024 11:53:24 +0000</pubDate>
      <link>https://dev.to/abharangupta/dive-into-jackson-for-json-in-java-understanding-jsonnode-arraynode-and-objectmapper-30g4</link>
      <guid>https://dev.to/abharangupta/dive-into-jackson-for-json-in-java-understanding-jsonnode-arraynode-and-objectmapper-30g4</guid>
      <description>&lt;p&gt;Hey, fellow Java devs! 🚀&lt;/p&gt;

&lt;p&gt;Ever find yourself staring at JSON data and thinking, "How on earth do I work with this in Java?" Don't worry - you're not alone! Whether it's building APIs, consuming them, or just handling data, dealing with JSON is almost inevitable. But here's the good news: &lt;strong&gt;Jackson&lt;/strong&gt; has your back!&lt;/p&gt;

&lt;p&gt;In this article, I'm going to walk you through some Jackson basics, like &lt;strong&gt;JsonNode, ArrayNode, and the ObjectMapper&lt;/strong&gt;. We'll keep it simple, with easy code examples and outputs to show you exactly how things work.&lt;/p&gt;

&lt;p&gt;Sound good? Let's dive in! 🔍&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up Jackson in a Spring Boot Project
&lt;/h2&gt;

&lt;p&gt;Before we dive into the examples, let's quickly cover how to set up Jackson in a Spring Boot project. Good news: Spring Boot has Jackson built-in, so there's minimal setup required. 🎉&lt;/p&gt;

&lt;p&gt;When you create a new Spring Boot project, Jackson comes as the default JSON library for serialization and deserialization. If you want to explicitly add Jackson, ensure the following dependency is in your &lt;code&gt;pom.xml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;com.fasterxml.jackson.core&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;jackson-databind&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;2.18.0&amp;lt;/version&amp;gt; &amp;lt;!-- You can use the latest version --&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will add Jackson's core functionality, including &lt;code&gt;ObjectMapper&lt;/code&gt;, for JSON handling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bonus: Spring Boot Configuration&lt;/strong&gt;&lt;br&gt;
Spring Boot provides an out-of-the-box setup for Jackson, but you can also customize it via the &lt;code&gt;application.properties&lt;/code&gt; or &lt;code&gt;application.yml&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;For example, to configure pretty-printing of JSON, you can add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;spring.jackson.serialization.indent_output=true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or in &lt;code&gt;application.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;spring:
  jackson:
    serialization:
      indent_output: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, whenever your Spring Boot app serializes JSON, it will be nicely formatted!&lt;/p&gt;

&lt;p&gt;With this setup done, you're ready to work with JSON in your Spring Boot app using Jackson.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, What Is Jackson?
&lt;/h2&gt;

&lt;p&gt;Jackson is like a Swiss Army knife for working with JSON in Java. You can use it to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1. Convert Java objects to JSON (serialization).&lt;/li&gt;
&lt;li&gt;2. Convert JSON to Java objects (deserialization).&lt;/li&gt;
&lt;li&gt;3. Handle JSON in a tree-like structure with JsonNode.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We're going to explore some of these features today, so get ready to make JSON handling feel a lot less scary!&lt;/p&gt;

&lt;h2&gt;
  
  
  JsonNode: Your First Step into JSON
&lt;/h2&gt;

&lt;p&gt;Think of JsonNode as a magical key that lets you explore and manipulate JSON data. It's a way of representing different parts of a JSON structure in Java.&lt;/p&gt;

&lt;p&gt;Imagine you've got this simple JSON data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "Samarth",
  "age": 30,
  "city": "New York"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How do you read this in Java? Let's see!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here's the code:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonNodeExample {
    public static void main(String[] args) throws Exception {
        String jsonString = "{\"name\":\"Samarth\", \"age\":30, \"city\":\"New York\"}";

        // Step 1: Create an ObjectMapper
        ObjectMapper objectMapper = new ObjectMapper();

        // Step 2: Parse the JSON string into a JsonNode
        JsonNode jsonNode = objectMapper.readTree(jsonString);

        // Step 3: Access values from the JsonNode
        System.out.println("Name: " + jsonNode.get("name").asText());
        System.out.println("Age: " + jsonNode.get("age").asInt());
        System.out.println("City: " + jsonNode.get("city").asText());
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;And the output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Name: Samarth  
Age: 30  
City: New York
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What's happening here?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;ObjectMapper&lt;/strong&gt; is Jackson's main helper. It's the one that translates between JSON and Java.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;readTree()&lt;/code&gt; reads the JSON and converts it into a JsonNode object.&lt;/li&gt;
&lt;li&gt;We use &lt;code&gt;.get()&lt;/code&gt; to access the individual fields-&lt;code&gt;"name"&lt;/code&gt;, &lt;code&gt;"age"&lt;/code&gt;, and &lt;code&gt;"city"&lt;/code&gt;-from the JSON.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Pretty cool, right? Now you're starting to see how easy it is to work with JSON in Java!&lt;/p&gt;

&lt;h2&gt;
  
  
  ArrayNode: Handling JSON Arrays
&lt;/h2&gt;

&lt;p&gt;But what if your JSON is an array? Don't worry, Jackson has that covered too! Let's say you have this JSON array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  {"name": "Samarth"},
  {"name": "Ujjwal"},
  {"name": "Gaurav"}
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can use ArrayNode to read and work with this array of objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here's the code:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;

public class ArrayNodeExample {
    public static void main(String[] args) throws Exception {
        String jsonArrayString = "[{\"name\":\"Samarth\"}, {\"name\":\"Ujjwal\"}, {\"name\":\"Gaurav\"}]";

        // Step 1: Create an ObjectMapper
        ObjectMapper objectMapper = new ObjectMapper();

        // Step 2: Parse the JSON array into an ArrayNode
        ArrayNode arrayNode = (ArrayNode) objectMapper.readTree(jsonArrayString);

        // Step 3: Loop through each element in the array
        for (JsonNode jsonNode : arrayNode) {
            System.out.println("Name: " + jsonNode.get("name").asText());
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Name: Samarth
Name: Ujjwal
Name: Gaurav
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What's happening here?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;ArrayNode&lt;/strong&gt; is a special type of &lt;strong&gt;JsonNode&lt;/strong&gt; that represents an array of JSON objects.&lt;/li&gt;
&lt;li&gt;We loop through each element in the array and print out the "name" of each person.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Easy, right? With &lt;strong&gt;ArrayNode&lt;/strong&gt;, Jackson makes handling JSON arrays a breeze!&lt;/p&gt;

&lt;h2&gt;
  
  
  ObjectMapper: The Heart of Jackson
&lt;/h2&gt;

&lt;p&gt;Now, let's talk about &lt;strong&gt;ObjectMapper&lt;/strong&gt; - the heart and soul of Jackson. It's your go-to tool for converting Java objects to JSON and vice versa.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Serializing Java Objects to JSON&lt;/strong&gt;&lt;br&gt;
Serialization is just a fancy way of saying, "turn my Java object into a JSON string." Let's say you have a simple &lt;code&gt;Person&lt;/code&gt;class:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import com.fasterxml.jackson.databind.ObjectMapper;

public class SerializationExample {
    public static void main(String[] args) throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();

        // Step 1: Create a Java object
        Person person = new Person("Samarth", 30, "New York");

        // Step 2: Convert the Java object to JSON (serialization)
        String jsonString = objectMapper.writeValueAsString(person);

        // Output the JSON
        System.out.println("Serialized JSON: " + jsonString);
    }
}

class Person {
    private String name;
    private int age;
    private String city;

    public Person(String name, int age, String city) {
        this.name = name;
        this.age = age;
        this.city = city;
    }

    public String getName() { return name; }
    public int getAge() { return age; }
    public String getCity() { return city; }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Serialized JSON: {"name":"Samarth","age":30,"city":"New York"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What's happening here?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;ObjectMapper&lt;/strong&gt; takes the &lt;code&gt;Person&lt;/code&gt;object and converts it into a JSON string using &lt;code&gt;writeValueAsString()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The method &lt;code&gt;writeValueAsString()&lt;/code&gt; creates a JSON representation of the Java object.&lt;/li&gt;
&lt;li&gt;The result is a valid JSON string you can send to an API or store in a database.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Deserializing JSON to a Java Object
&lt;/h2&gt;

&lt;p&gt;And it works the other way around too! You can take JSON and turn it back into a Java object. This is called &lt;strong&gt;deserialization&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Here's the code:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import com.fasterxml.jackson.databind.ObjectMapper;

public class DeserializationExample {
    public static void main(String[] args) throws Exception {
        String jsonString = "{\"name\":\"Samarth\", \"age\":30, \"city\":\"New York\"}";

        ObjectMapper objectMapper = new ObjectMapper();

        // Step 1: Convert the JSON string to a Java object (deserialization)
        Person person = objectMapper.readValue(jsonString, Person.class);

        // Output the Java object
        System.out.println("Deserialized Object: " + person.getName() + ", " + person.getAge() + ", " + person.getCity());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Deserialized Object: Samarth, 30, New York
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What's happening here?
&lt;/h2&gt;

&lt;p&gt;We use &lt;strong&gt;ObjectMapper&lt;/strong&gt; again, but this time it reads a JSON string and converts it back into a &lt;code&gt;Person&lt;/code&gt; object.&lt;br&gt;
This is done using &lt;code&gt;readValue()&lt;/code&gt;, and the result is a full Java object ready to be used in your code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;And there you have it! We've covered a lot of ground:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;JsonNode&lt;/strong&gt;: How to read and manipulate JSON data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ArrayNode&lt;/strong&gt;: How to handle JSON arrays.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ObjectMapper&lt;/strong&gt;: How to serialize and deserialize Java objects to and from JSON.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope this guide makes Jackson a little less intimidating and a lot more fun to use! Once you get the hang of it, you'll be handling JSON like a pro in no time.&lt;/p&gt;

&lt;p&gt;But hey, don't stop here! Keep an eye out for my next article where we'll dive deeper into more advanced Jackson features and best practices for real-world applications.&lt;/p&gt;

&lt;p&gt;See you next time! Happy coding! 😄&lt;/p&gt;

</description>
      <category>java</category>
      <category>json</category>
      <category>softwareengineering</category>
      <category>developer</category>
    </item>
  </channel>
</rss>
