<?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 Talha Ansari on Medium]]></title>
        <description><![CDATA[Stories by Talha Ansari on Medium]]></description>
        <link>https://medium.com/@zeusdante.die?source=rss-1b4392950216------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*B7nrA01pfEL6-bi4peiArg@2x.jpeg</url>
            <title>Stories by Talha Ansari on Medium</title>
            <link>https://medium.com/@zeusdante.die?source=rss-1b4392950216------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 22:29:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zeusdante.die/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[Maintain API versioning in efficient way in SpringBoot App.]]></title>
            <link>https://medium.com/@zeusdante.die/maintain-api-versioning-in-efficeinet-way-in-springboot-app-b9fe371b0dae?source=rss-1b4392950216------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9fe371b0dae</guid>
            <dc:creator><![CDATA[Talha Ansari]]></dc:creator>
            <pubDate>Wed, 15 May 2024 15:58:37 GMT</pubDate>
            <atom:updated>2024-06-28T19:34:19.486Z</atom:updated>
            <content:encoded><![CDATA[<p>How to maintain API versioning in efficeinet without effecting DTOS and Service classes in SpringBoot by using Jackson and Spring Validation API.</p><p>Mainaing API version is realy annoying in existing Microservice. But we have lots of way to maintain versioning.</p><p>Here we use <em>Jackson </em>and <em>Spring Validation API</em> to maintain API versioning.</p><p>Here we are going to mangeUser Registration v1 and v2 api.</p><p>First of All you have to create a class which must <em>Interface/Class</em> just like below. It use to represent v1 and v2 in term of api versioning.</p><pre>public class RegistrationVersion {<br>    public interface V1 {}<br><br>    public interface V2 { }<br>}</pre><p>After that you have to use <em>@JsonView</em> Annotation on the top of class and you can also use field level and pass above class and its nested interface also you can use nested level of User Request.</p><pre>@Getter<br>@Setter<br>@NoArgsConstructor<br>@AllArgsConstructor<br>@JsonView(value = {RegistrationVersion.V1.class,RegistrationVersion.V2.class})<br>public class UserRegistrationDTO {<br>    @Email(message = &quot;Invalid email id&quot;)<br>    private String customerId;<br><br>    @NotNull<br>    private String userName;<br><br>    @Size(min = 4, max = 20,message = &quot;Password length between 4 to 20&quot;)<br>    private String pass;<br><br><br>    @Size(min = 8, max = 8,message = &quot;Must be 8 digit&quot;)<br>    private String voucherCode;<br><br>    @NotNull(message = &quot; DemographicDetails should not empty.&quot;)<br>    @Valid<br>    private DemographicDetails demographicDetails;<br><br>}</pre><p>For Spring Validation you must have to pass in annotation like <em>@NotNull(groups=Registration.V1.class)</em> in group.</p><pre>@Getter<br>@Setter<br>@NoArgsConstructor<br>@AllArgsConstructor<br>@JsonView(value = {RegistrationVersion.V1.class,RegistrationVersion.V2.class})<br>public class DemographicDetails {<br><br>    private Address address;<br>    private String propertyType;<br>    @NotNull(message = &quot;flatRegistrationNo should not null&quot;,groups = RegistrationVersion.V2.class)<br>    @JsonView(RegistrationVersion.V2.class)<br>    private String flatRegistrationNo;<br>    private Integer numberOfBedRoom;<br>}</pre><pre>@Getter<br>@Setter<br>@NoArgsConstructor<br>@AllArgsConstructor<br>public class Address {<br>    private String flatNo;<br>    private String area;<br>    private String landmark;<br>    private Long pinCode;<br>}</pre><p>In controller class you must have to use <em>@JsonView(value=Registration.V2.class)</em> and also use <em>@Validated(Registration.V2.class)</em> at controller level.</p><pre>@Slf4j<br>@RestController<br>@RequiredArgsConstructor<br>public class CustomerRegistration {<br><br>    private final CustomerService userMasterService;<br>    @PostMapping(path = &quot;v1/register&quot;, produces = MediaType.APPLICATION_JSON_VALUE)<br>    public ResponseEntity&lt;Object&gt; userRegistrationV1(<br>            @RequestBody @Valid @JsonView(RegistrationVersion.V1.class) UserRegistrationDTO userRegistrationDTO) {<br>        userMasterService.saveUser(userRegistrationDTO);<br>        return ResponseEntity.status(HttpStatus.CREATED).build();<br>    }<br>    @PostMapping(path = &quot;v2/register&quot;, produces = MediaType.APPLICATION_JSON_VALUE)<br>    public ResponseEntity&lt;Object&gt; userRegistrationV2(<br>            @RequestBody @Validated(RegistrationVersion.V2.class)<br>            @JsonView(RegistrationVersion.V2.class) UserRegistrationDTO userRegistrationDTO) {<br>        userMasterService.saveUser(userRegistrationDTO);<br>        return ResponseEntity.status(HttpStatus.CREATED).build();<br>    }<br>}</pre><p><strong><em>Conclusion</em></strong>: When ever user send request V1 it will desrialize field which annotated by Registration.V1.class also validate on those field which has done by Spring Validation. Its also work with V2 API same as V1.</p><p>**Its my first story if you got any issue pls comment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9fe371b0dae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>