<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sanidi Sisara on Medium]]></title>
        <description><![CDATA[Stories by Sanidi Sisara on Medium]]></description>
        <link>https://medium.com/@sanidi1113?source=rss-0a22c4626ea8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*SCOkabSN9em_dwaw1Fxaxg.jpeg</url>
            <title>Stories by Sanidi Sisara on Medium</title>
            <link>https://medium.com/@sanidi1113?source=rss-0a22c4626ea8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 12:14:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sanidi1113/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Getting Started with Ballerina: My First Experience Building with WSO2’s Cloud-Native Language]]></title>
            <link>https://medium.com/@sanidi1113/getting-started-with-ballerina-my-first-experience-building-with-wso2s-cloud-native-language-fbdcbd5dc0bc?source=rss-0a22c4626ea8------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbdcbd5dc0bc</guid>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[ballerina]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[beginner-developers]]></category>
            <dc:creator><![CDATA[Sanidi Sisara]]></dc:creator>
            <pubDate>Tue, 14 Oct 2025 15:19:52 GMT</pubDate>
            <atom:updated>2025-10-14T16:35:47.783Z</atom:updated>
            <content:encoded><![CDATA[<h4>An introduction to WSO2’s Ballerina language for beginners through my lessons and insights</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wMfIzarR38O3OjKvFCjULA.png" /></figure><h3>Introduction: Discovering Ballerina</h3><p>When I first heard about <strong>Ballerina</strong>, I was curious but cautious. As someone who had been coding mainly in <strong>Java</strong>, especially with <strong>Spring Boot</strong>, I wondered why we need another programming language. Then I started exploring it for my project submission, <strong>AyurConnect</strong> to the <strong>Innovate with Ballerina 2025</strong> competition and that’s when things got interesting.</p><p>I realized Ballerina isn’t just another programming language. It’s built with a clear purpose: <strong>making cloud-native and integration development simpler, cleaner, and faster</strong>. In this article, I’ll share my journey as a beginner exploring Ballerina, what makes it unique, and why I think it’s worth trying, especially if you’re a Java developer stepping into cloud-native development.</p><h3>What Exactly Is Ballerina?</h3><p><strong>Ballerina</strong> is an open-source, cloud-native programming language created by <strong>WSO2</strong>. It’s designed for developers building networked applications,<strong> </strong>APIs, integrations, and microservices.</p><p>What makes it special is that networking isn’t an afterthought; it’s at the core of the language. Instead of relying on external frameworks or libraries for integration, Ballerina comes with those features built right in.</p><p>Think of Java as a general-purpose all-rounder, great for almost anything.<br>Then think of Ballerina as the specialist; a tool that focuses on one goal: <strong>simplifying how services communicate in the cloud</strong>.</p><h3>Key Features That Caught My Eye</h3><p>When I started learning Ballerina, a few features immediately stood out:</p><ul><li><strong>Network-Aware Design</strong> — Built-in support for HTTP, gRPC, GraphQL, WebSockets, and more.</li><li><strong>Data-Oriented Programming</strong> — Native handling of JSON, XML, and records.</li><li><strong>Visual Code Representation</strong> — You can view your code as sequence diagrams inside VS Code!</li><li><strong>Cloud-Native Support</strong> — Direct deployment to Docker and Kubernetes.</li></ul><p>These features felt modern and developer-focused; they solved many small frustrations I had when wiring up services in Java.</p><h3>Similarities That Made the Transition from Java to Ballerina Easy</h3><p>As a Java developer, Ballerina felt surprisingly natural to read. Its syntax borrows a lot from Java, so I wasn’t starting from zero.</p><ul><li><strong>Familiar Syntax Foundation</strong><br>Ballerina’s syntax has Java-like elements, making it approachable for Java developers:</li></ul><pre>// Variable declaration (similar to Java)<br>string name = &quot;AyurConnect&quot;;<br>int port = 9090;<br><br>// Functions (familiar structure)<br>function greet(string name) returns string {<br>    return &quot;Hello, &quot; + name;<br>}</pre><ul><li><strong>Object-Oriented Concepts</strong><br>While Ballerina isn’t purely OOP like Java, it supports similar concepts:</li></ul><pre>// Type definitions (like classes)<br>type Patient record {|<br>    string id;<br>    string name;<br>    int age;<br>    string condition;<br>|};</pre><ul><li><strong>Strong Type System</strong><br>Both languages have robust type systems, though Ballerina’s is more focused on data:</li></ul><pre>// Union types (more flexible than Java)<br>type Response string|int|error;<br><br>// Type narrowing<br>function processResponse(Response resp) {<br>    if resp is string {<br>        io:println(&quot;String response: &quot; + resp);<br>    } else if resp is int {<br>        io:println(&quot;Integer response: &quot; + resp.toString());<br>    }<br>}</pre><h3>Understanding a Ballerina Project</h3><p>Before writing any code, I explored what a basic Ballerina project looks like. It’s organized, minimal, and easy to understand.</p><h4>Key Files and Folders in a Ballerina Project</h4><ul><li><strong>Ballerina.toml</strong> – Defines project information and dependencies (similar to pom.xml in Java).</li><li><strong>Dependencies.toml</strong> – Similar to package-lock.json in Node.js, this ensures reproducible builds by locking dependency versions.</li><li><strong>Config.toml</strong> – Stores environment-specific configurations.</li><li><strong>main.bal</strong> – The main service file where the application starts.</li><li><strong>modules/</strong> – Organizes reusable components (similar to Java packages).</li></ul><p>This simplicity made it beginner-friendly; no complex XML files or multiple configuration layers.</p><h3>A Glimpse at the Code</h3><p>Let’s look at what a simple Ballerina service might look like.</p><pre>import ballerina/http;<br><br>service / on new http:Listener(9090) {<br><br>    resource function get hello(string name) returns string {<br>        return &quot;Hello, &quot; + name + &quot;!&quot;;<br>    }<br>}</pre><p>That’s it; no annotations, no controller setup.If you run this file (bal run), you’ll instantly have a running REST endpoint.</p><h3>Challenges I Faced as a Beginner</h3><p>Of course, the journey wasn’t without challenges:</p><ul><li><strong>Smaller Ecosystem:</strong> It doesn’t have as many third-party libraries as Java yet.</li><li><strong>New Concepts:</strong> Features like union types took some getting used to.</li><li><strong>IDE Limitations:</strong> The VS Code extension works well, but it’s still evolving.</li></ul><p>However, the <strong>official documentation</strong> and <strong>community resources</strong> made learning much easier. Once I grasped the fundamentals, everything started to feel logical and powerful.</p><h3>When Should You Try Ballerina?</h3><p>Choose Ballerina if you’re building:</p><ul><li>APIs or microservices that need to integrate with other systems</li><li>Cloud-native or event-driven applications</li><li>Data transformation and connectivity workflows</li></ul><p>Stick to Java when you:</p><ul><li>Maintain large enterprise systems</li><li>Depend on Java’s vast library ecosystem</li><li>Need frameworks tailored to enterprise-scale workloads</li></ul><h3>Conclusion: A Beginner’s Takeaway</h3><p>Exploring Ballerina was a refreshing experience. It simplified many of the things that usually take extra setup in Java; especially for APIs and integrations.</p><p>It’s not trying to replace Java or any existing language. Instead, <strong>Ballerina fills a unique gap</strong>: it’s made for modern, cloud-native, connected systems.</p><p>As a Java developer, I found it easy to pick up and surprisingly fun to use. It’s clean, visual, and purpose-built for integration, and that’s what makes it exciting.</p><p>If you’re curious about simplifying API and microservice development, I’d highly recommend giving Ballerina a try. It’s beginner-friendly yet powerful enough for real-world use.</p><p><em>I’m still exploring and learning more about Ballerina. If you’re a fellow beginner, let’s keep sharing and growing together. Happy coding!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbdcbd5dc0bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React vs Next.js: Lessons From My Frontend Journey]]></title>
            <link>https://medium.com/@sanidi1113/react-vs-next-js-lessons-from-my-frontend-journey-974ef589035a?source=rss-0a22c4626ea8------2</link>
            <guid isPermaLink="false">https://medium.com/p/974ef589035a</guid>
            <category><![CDATA[beginner-developers]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Sanidi Sisara]]></dc:creator>
            <pubDate>Fri, 26 Sep 2025 04:02:44 GMT</pubDate>
            <atom:updated>2025-09-26T04:04:38.630Z</atom:updated>
            <content:encoded><![CDATA[<h4>A beginner’s take on when to use React and when Next.js makes life easier</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5NOcqBoE1gpJaVkZs8TFeA.png" /></figure><p>When I first started learning frontend development, I kept hearing about <strong>React</strong> and <strong>Next.js</strong>. I knew they were popular, but I honestly didn’t understand the difference.</p><p>Then came my first big project: <strong>Voluntrix</strong>, a volunteering event management platform I worked on with my team. We chose <strong>Next.js</strong> — and while at the start I didn’t know why, the experience helped me understand how React and Next.js fit into the frontend world.</p><p>This article is not a deep technical breakdown. Instead, it’s a <strong>beginner-friendly comparison</strong>, based on what I learned while building a real-world project.</p><h3>What is React?</h3><p>React is a <strong>JavaScript library</strong> that helps you build user interfaces (UIs). Imagine you’re building a webpage that has buttons, forms, and cards. Instead of writing the whole page in one big file, React lets you break it down into <strong>components</strong> — small, reusable pieces.</p><h3>Some key things about React:</h3><ul><li>It focuses only on the <strong>view layer</strong> (how things look and behave on the screen).</li><li>It’s flexible, meaning you can add other tools when you need them. For example:</li></ul><blockquote><strong>React Router</strong> for navigation between pages.</blockquote><blockquote><strong>Redux</strong> (or other libraries) for managing data across the app.</blockquote><ul><li>It’s one of the most widely used frontend libraries, with a huge community.</li></ul><p>But here’s the catch: with React alone, you need to set up a lot of things yourself. Want SEO? Want server-side rendering? Want easy routing? You’ll need to add extra tools.</p><h3>What is Next.js?</h3><p>Next.js is like React, but with <strong>extra powers</strong>. It’s a <strong>framework built on top of React</strong>, meaning it uses React at its core but adds many features that developers usually need.</p><p>Some highlights of Next.js:</p><ul><li><strong>File-based routing</strong> → You don’t need to configure React Router. Just create a file in the pages (or app) folder, and it automatically becomes a route.</li><li><strong>Rendering options</strong> → Unlike React (which only renders on the client side), Next.js supports:</li></ul><blockquote><strong>SSR (Server-Side Rendering)</strong> — pages are prepared on the server before reaching the browser.</blockquote><blockquote><strong>SSG (Static Site Generation)</strong> — pages are generated once and served quickly.</blockquote><blockquote><strong>CSR (Client-Side Rendering)</strong> — same as React.</blockquote><ul><li><strong>SEO-friendly by default</strong> → Since pages can be rendered on the server, search engines can easily read them.</li><li><strong>Easy deployment</strong> → Especially smooth with <strong>Vercel</strong>, the platform created by the same team behind Next.js.</li></ul><p>In short: <strong>React gives you the building blocks, while Next.js gives you a whole toolbox.</strong></p><h3>My Experience With Next.js in Voluntrix</h3><p>In our Voluntrix project, choosing Next.js turned out to be a good decision. Here’s why:</p><ol><li><strong>Routing was effortless</strong> → With the App Router, creating routes was as simple as adding folders and page.tsx files. No extra setup.</li><li><strong>Deployment was painless</strong> → With Vercel, deploying was as simple as connecting our GitHub repo.</li><li><strong>SEO was built-in</strong> → Since event pages were public, SSR helped make them more visible on search engines.</li><li><strong>Smooth developer experience</strong> → Combining Next.js with TypeScript and Tailwind CSS felt natural and productive.</li></ol><p>As a beginner, I found that Next.js <strong>hid the complicated setup</strong> and let me focus on building actual features.</p><h3>When React Makes More Sense</h3><p>There are definitely times when plain React is the better choice:</p><ul><li><strong>Learning the basics</strong> → If you’re just starting out, React helps you understand core frontend concepts.</li><li><strong>Small apps or widgets</strong> → Things like dashboards, admin panels, or a simple to-do list app don’t really need SSR or SEO.</li><li><strong>More control</strong> → If you want to handpick every library and customize everything, React gives you that freedom.</li></ul><h3>When Next.js Shines</h3><p>Next.js is best suited for:</p><ul><li><strong>Public-facing apps that need SEO</strong> → blogs, e-commerce sites, or event platforms.</li><li><strong>Bigger projects</strong> → where routing, server-side rendering, and performance matter.</li><li><strong>Teams that want speed</strong> → less time spent on setup, more time on features.</li><li><strong>Easy hosting</strong> → Vercel makes deployment almost effortless.</li></ul><p>In our case with Voluntrix, since the platform needed SEO, dynamic routing, and smooth deployment, Next.js was the clear winner.</p><h3>React vs Next.js: Key Differences</h3><p><strong>1. Type:</strong></p><ul><li>React → A <em>library</em> for building UIs.</li><li>Next.js → A <em>framework</em> built on React, with extra features.</li></ul><p><strong>2. Routing:</strong></p><ul><li>React → Needs React Router or another library for navigation.</li><li>Next.js → Built-in App Router (or Pages Router).</li></ul><p><strong>3. Rendering:</strong></p><ul><li>React → Only client-side rendering.</li><li>Next.js → Supports SSR, SSG, ISR, and CSR.</li></ul><p><strong>4. SEO:</strong></p><ul><li>React → Needs extra configuration for SEO.</li><li>Next.js → SEO-friendly by default.</li></ul><p><strong>5. Deployment:</strong></p><ul><li>React → Flexible, but setup depends on your hosting.</li><li>Next.js → Optimized for Vercel, very beginner-friendly.</li></ul><p><strong>6. Best Use Cases:</strong></p><ul><li>React → Small apps, learning, or when you want full flexibility.</li><li>Next.js → Larger apps, SEO-heavy projects, fast prototyping, and production-ready apps.</li></ul><h3>Final Thoughts</h3><p>At the end of the day:</p><ul><li><strong>React is the foundation.</strong> It teaches you how to think in components and manage state.</li><li><strong>Next.js is the toolkit.</strong> It saves you time by solving common problems upfront.</li></ul><p>From my journey with Voluntrix, Next.js gave us <strong>speed, SEO benefits, and smooth deployment</strong>. But I also realized that having a good understanding of React itself is important — you need the foundation before enjoying the framework.</p><p>So if you’re a beginner:</p><ul><li>Start with <strong>React</strong> to learn the basics.</li><li>Move to <strong>Next.js</strong> when you’re ready to build a real-world app.</li></ul><p><em>What about you? Have you used React or Next.js in your projects? I’d love to hear about your experience in the comments.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=974ef589035a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enums in Java: Tiny Feature, Huge Impact on Code]]></title>
            <link>https://medium.com/@sanidi1113/enums-in-java-tiny-feature-huge-impact-on-code-6db204d5f02a?source=rss-0a22c4626ea8------2</link>
            <guid isPermaLink="false">https://medium.com/p/6db204d5f02a</guid>
            <category><![CDATA[enum]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-basics]]></category>
            <category><![CDATA[backend-development]]></category>
            <dc:creator><![CDATA[Sanidi Sisara]]></dc:creator>
            <pubDate>Sat, 06 Sep 2025 17:07:06 GMT</pubDate>
            <atom:updated>2025-09-06T17:07:06.081Z</atom:updated>
            <content:encoded><![CDATA[<h4>A beginner’s journey with enums — mistakes included — while working on my first Java project</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h1ftL5v3e3ZXKKNOViI7VA.png" /></figure><p>When I first started working on <strong>Voluntrix</strong>, our volunteering event management platform, I had absolutely no idea what an <strong>enum</strong> was or why it was even needed. I was used to working with strings and integers for almost everything, and enums felt like some “extra complexity” I didn’t want to deal with.</p><p>But as the project grew, I quickly realized enums are not just a “Java feature” — they are a <strong>lifesaver for keeping code clean, safe, and error-free</strong>. In this article, I’ll share what enums are, how we used them in Voluntrix, and a mistake I made (that cost me an hour of debugging) so you don’t repeat it.</p><h3>What Are Enums in Java?</h3><p>Enums (short for <strong>enumerations</strong>) are a special data type that lets you define a <strong>fixed set of related values</strong>.Think of it like creating your own category with only a few allowed options. For example:</p><ul><li>Days of the week → MONDAY, TUESDAY, WEDNESDAY …</li><li>Directions → NORTH, SOUTH, EAST, WEST</li><li>Event status → DRAFT, ACTIVE, COMPLETE …</li></ul><p>Instead of using plain strings like &quot;ACTIVE&quot; or &quot;PENDING&quot; (which are easy to mistype and hard to maintain), you can define an enum in Java:</p><pre>public enum EventStatus {<br>    DRAFT,<br>    PENDING,<br>    ACTIVE,<br>    COMPLETE,<br>    DENIED<br>}</pre><p>Now, anywhere in the code, if I use EventStatus.ACTIVE, Java ensures that only these valid values are allowed — nothing outside the list. No more typos like &quot;ACTIVEE&quot; silently breaking my code.</p><blockquote><strong>Why enum values are usually written in all caps:</strong><br>By convention, enum constants in Java are written in <strong>uppercase letters</strong>. This makes them <strong>stand out</strong> in your code and immediately signals that they are fixed constants. While it’s technically possible to use lowercase or camelCase, it’s best to stick with uppercase for clarity and consistency, especially when working with teams or larger projects.</blockquote><h3>How We Used Enums in Voluntrix</h3><p>Our project had several enums. Here are the main ones in the <strong>Event module</strong>:</p><pre>public enum EventStatus {<br>    DRAFT,<br>    PENDING,<br>    ACTIVE,<br>    COMPLETE,<br>    DENIED<br>}<br><br>public enum EventType {<br>    ONLINE,<br>    ONSITE<br>}<br><br>public enum EventVisibility {<br>    PRIVATE,<br>    PUBLIC<br>}</pre><p>These enums represented the <strong>state, type, and visibility</strong> of an event. Using enums made it easier to manage workflows and avoid hard-coded strings scattered all over the codebase.</p><h3>Enums in Entities</h3><p>When using enums inside a <strong>database entity class</strong>, you need to tell Java how to save them in the database. By default, enums can be stored as numbers (0, 1, 2…) based on their order, but that can be confusing later on.</p><p>That’s why we use the annotation:</p><pre>@Enumerated(EnumType.STRING)</pre><p>This ensures enums are stored as their <strong>string values</strong> (e.g., &quot;ACTIVE&quot;, &quot;COMPLETE&quot;) instead of just positions. It makes the database more readable and avoids errors if the enum order changes in the future.</p><p>Here’s how part of our EventEntity looked:</p><pre>@Entity<br>public class EventEntity {<br>    @Id<br>    @GeneratedValue(strategy = GenerationType.IDENTITY)<br>    private Long eventId;<br><br>    private String eventTitle;<br><br>    @Enumerated(EnumType.STRING)<br>    private EventType eventType; // ONLINE or ONSITE<br><br>    @Enumerated(EnumType.STRING)<br>    private EventVisibility eventVisibility; // PRIVATE or PUBLIC<br><br>    @Enumerated(EnumType.STRING)<br>    private EventStatus eventStatus; // DRAFT, PENDING, ACTIVE, COMPLETE, DENIED<br>}</pre><h3>My Big Mistake (and What I Learned)</h3><p>At one point, I wrote a query in EventApplicationRepository.java to fetch applied events for a volunteer:</p><pre>@Query(&quot;SELECT new com.DevSprint.voluntrix_backend.dtos.VolunteerAppliedEventDTO(&quot; +<br>       &quot;ea.id, e.eventTitle, e.eventType, ea.contributionArea) &quot; +<br>       &quot;FROM EventApplicationEntity ea &quot; +<br>       &quot;JOIN ea.event e &quot; +<br>       &quot;WHERE ea.volunteer.id = :volunteerId AND ea.applicationStatus = &#39;PENDING&#39;&quot;)<br>List&lt;VolunteerAppliedEventDTO&gt; findAppliedEventsByVolunteerId(@Param(&quot;volunteerId&quot;) Long volunteerId);</pre><p>In my <strong>DTO</strong> (Data Transfer Object — if you’re new to this concept, I explained it in detail in <a href="https://medium.com/@sanidi1113/dtos-in-spring-boot-lessons-from-my-first-real-project-e81fed0ad07c">my previous article on DTOs </a>), I mistakenly declared eventType as a <strong>String</strong>:</p><pre>public class VolunteerAppliedEventDTO {<br>    private Long applicationId;<br>    private String eventName;<br>    private String eventType; // Wrong attribute type<br>}</pre><p>This caused errors when mapping results because the query was returning an EventType enum, not a string. I spent <strong>an hour debugging</strong> this small mistake.</p><p>The fix was simple:</p><pre>public class VolunteerAppliedEventDTO {<br>    private Long applicationId;<br>    private String eventName;<br>    private EventType eventType; // Correct attribute type<br>}</pre><p>Lesson learned:<br>When dealing with queries and DTOs, always ensure the data type matches the entity’s attribute type — especially if it’s an enum.</p><h3>Why Enums Are Worth It</h3><p>After this experience, enums became one of my favorite tools in Java. Here’s why I recommend always using them when possible:</p><ul><li><strong>Type safety</strong> → prevents invalid values (no more random strings floating around).</li><li><strong>Readability</strong> → enums make code self-explanatory.</li><li><strong>Consistency</strong> → one definition, reusable everywhere.</li><li><strong>Less debugging</strong> → small mistakes are caught at compile-time.</li></ul><h3>Final Thoughts</h3><p>When I started with Voluntrix, I thought enums were unnecessary. Now, I can’t imagine building a real project without them.</p><p>If you’re a beginner, my advice is: <strong>take enums seriously early on</strong>. They may look like just another Java feature, but they’ll save you hours of debugging and make your code much cleaner.</p><p>And if you ever catch yourself writing &quot;ACTIVE&quot; as a plain string somewhere… stop and make it an enum. Your future self will thank you.</p><p><em>That’s my journey with enums in Java. Have you ever made a silly enum mistake like me? I’d love to hear your story in the comments!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6db204d5f02a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DTOs in Spring Boot: Lessons from My First Real Project]]></title>
            <link>https://medium.com/@sanidi1113/dtos-in-spring-boot-lessons-from-my-first-real-project-e81fed0ad07c?source=rss-0a22c4626ea8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e81fed0ad07c</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[dto]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[beginner-developers]]></category>
            <dc:creator><![CDATA[Sanidi Sisara]]></dc:creator>
            <pubDate>Fri, 05 Sep 2025 18:23:52 GMT</pubDate>
            <atom:updated>2025-09-05T18:23:52.223Z</atom:updated>
            <content:encoded><![CDATA[<h4>A beginner’s journey with Spring Boot DTOs and why multiple DTOs saved my project.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oNuXrD8IuH-yHAflOAp81A.png" /></figure><h3>Introduction</h3><p>When I first started backend development for my project <strong>Voluntrix</strong> — a volunteering event management platform — I had no idea what a <strong>DTO (Data Transfer Object)</strong> was or why I should use it.</p><p>At the beginning, I created just a single VolunteerDTO.java file. But as I tested APIs in Swagger, I realized that having just one DTO was not enough. That’s when I discovered the importance of using multiple DTOs depending on the context: creating, retrieving, updating, or deleting data.</p><p>In this article, I’ll share my journey of learning about DTOs, the mistakes I made, and how I finally structured them for my <strong>Volunteer module</strong>.</p><h3>What is a DTO?</h3><p>A <strong>DTO (Data Transfer Object)</strong> is a simple Java object used to transfer data between layers in an application.</p><p>Think of it as a “data package” you send and receive through your APIs.</p><ul><li>It <strong>doesn’t contain business logic</strong>, only data.</li><li>It <strong>helps control what data is exposed</strong> to clients.</li><li>It <strong>decouples entities from API responses</strong>, making your code more secure and maintainable.</li></ul><blockquote><em>DTOs are about sending the </em>right<em> data, not </em>all<em> the data.</em></blockquote><h3>Why Not Just Use Entities Directly?</h3><p>At first, I thought — why not just use my entity classes directly? But I quickly ran into problems:</p><p><strong>Different use cases need different fields</strong></p><ul><li>Creating a volunteer doesn’t require all attributes.</li><li>Updating a volunteer should only allow specific fields.</li><li>Retrieving a volunteer should return all the details.</li></ul><p><strong>Security risks</strong></p><ul><li>Entities might expose sensitive fields you don’t want to leak.</li></ul><p><strong>Validation</strong></p><ul><li>DTOs allow you to apply validations (@Email, @NotNull, @Size) cleanly, without cluttering your entities.</li></ul><h3>My First Mistake: One DTO for Everything</h3><p>I started with just one DTO:</p><pre>public class VolunteerDTO {<br>    private Long volunteerId;<br>    private Long userId;<br>    private String username;<br>    private String fullName;<br>    private String email;<br>    private String institute;<br>    private String instituteEmail;<br>    private Boolean isAvailable;<br>    private Integer volunteerLevel;<br>    private Integer rewardPoints;<br>    private Boolean isEventHost;<br>    private String joinedDate;<br>    private String about;<br>    private String phoneNumber;<br>    private String profilePictureUrl;<br>}</pre><p>It worked fine for returning and deleting volunteer data, but when I tried using it for <strong>creating</strong> and <strong>updating</strong>, I hit issues:</p><ul><li>For <em>create</em>, I didn’t need fields like volunteerId or rewardPoints.</li><li>For <em>update</em>, I wanted to restrict which fields could be changed.</li></ul><h3>The Solution: Multiple DTOs</h3><p>I split my DTOs into <strong>three separate classes</strong>, each serving a clear purpose.</p><p>1. VolunteerDTO.java → <strong>For retrieving and deleting volunteer data</strong></p><p>This DTO contains <em>all the fields</em> related to a volunteer.</p><ul><li>It’s used when <strong>fetching volunteer information</strong>.</li><li>It also comes in handy for <strong>deleting a volunteer</strong>, since all related attributes need to be cleared when removing a volunteer from the system.</li></ul><p>2. VolunteerCreateDTO.java → <strong>For creating a volunteer</strong></p><p>Here I only included fields required for volunteer creation, and I added validations:</p><pre>public class VolunteerCreateDTO {<br>    private String institute;<br><br>    @Email(message = &quot;Institute email should be valid&quot;)<br>    private String instituteEmail;<br><br>    @NotNull(message = &quot;Availability status is required&quot;)<br>    private Boolean isAvailable;<br><br>    @Size(max = 255, message = &quot;About section can have at most 255 characters&quot;)<br>    private String about;<br><br>    @Size(max = 2048, message = &quot;Profile picture URL can have at most 2048 characters&quot;)<br>    private String profilePictureUrl;<br><br>    @Pattern(<br>      regexp = &quot;^(?:\\+94|0)?7\\d{8}$&quot;, <br>      message = &quot;Phone number must be a valid Sri Lankan mobile number&quot;)<br>    private String phoneNumber;<br>}</pre><p>3. VolunteerUpdateDTO.java → <strong>For updating volunteer data</strong></p><p>This DTO only allows modifying specific attributes:</p><pre>public class VolunteerUpdateDTO {<br>    private String institute;<br><br>    @Email(message = &quot;Institute email should be valid&quot;)<br>    private String instituteEmail;<br><br>    private Boolean isAvailable;<br><br>    @Size(max = 255, message = &quot;About section can have at most 255 characters&quot;)<br>    private String about;<br>}</pre><h3>Benefits I Saw</h3><p>After restructuring my DTOs, I noticed several improvements:</p><ul><li><strong>Cleaner API requests and responses</strong> — only relevant fields are included.</li><li><strong>Stronger validation</strong> — errors are caught early before reaching the database.</li><li><strong>Better maintainability</strong> — easier to extend in the future.</li><li><strong>Safer updates</strong> — volunteers can’t accidentally (or maliciously) modify fields they shouldn’t.</li></ul><h3>Final Thoughts</h3><p>Understanding DTOs was one of the first turning points in my backend journey, showing me how much cleaner and safer my code could be with the right structures. It taught me the importance of <strong>structuring data properly</strong> and not just going with the “quickest” solution.</p><p>If you’re starting out with Spring Boot, I highly recommend experimenting with DTOs early — they will save you a lot of headaches down the road.</p><p>I’m still learning, but building Voluntrix helped me see firsthand how <strong>multiple DTOs per module</strong> can make an application much more robust.</p><p><em>This was one of the first lessons that made me feel like I was growing as a backend developer. Maybe it’ll save you the same trial-and-error I went through. Happy coding, and may your journey be as rewarding as mine has been !</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e81fed0ad07c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>