Murray  Beatty

Murray Beatty

1594202655

Avoiding Boilerplate Code With MapStruct, Spring Boot and Kotlin

Building Spring Boot Rest Web Services might become cumbersome, especially when domain model objects need to be converted in many different DTOs (Data Transfer Object) and vice versa. Writing mapping manually is boring and involves boilerplate code. Is it possible to avoid it?

Yes, it is! Thanks to MapStructMapStruct is a Java annotation processor for the generation of type-safe and performant mappers for Java bean classes.

Integrating MapStruct with Spring Boot in Java is well documented (Automating Code with MapStruct), but what if we wanted to use** Kotlin**?

Let’s see how can MapStruct be integrated into a Spring Boot and Kotlin project.

1. Gradle dependency

Let’s add the Kapt compiler plugin and the MapStruct processor dependencies in build.gradle.kts.

plugins {
   kotlin("kapt") version "1.3.72"
}

dependencies {   
   kapt("org.mapstruct:mapstruct-processor:1.3.1.Final")
}

#dto #kotlin #spring-boot #mapstruct

What is GEEK

Buddha Community

Avoiding Boilerplate Code With MapStruct, Spring Boot and Kotlin
Murray  Beatty

Murray Beatty

1594202655

Avoiding Boilerplate Code With MapStruct, Spring Boot and Kotlin

Building Spring Boot Rest Web Services might become cumbersome, especially when domain model objects need to be converted in many different DTOs (Data Transfer Object) and vice versa. Writing mapping manually is boring and involves boilerplate code. Is it possible to avoid it?

Yes, it is! Thanks to MapStructMapStruct is a Java annotation processor for the generation of type-safe and performant mappers for Java bean classes.

Integrating MapStruct with Spring Boot in Java is well documented (Automating Code with MapStruct), but what if we wanted to use** Kotlin**?

Let’s see how can MapStruct be integrated into a Spring Boot and Kotlin project.

1. Gradle dependency

Let’s add the Kapt compiler plugin and the MapStruct processor dependencies in build.gradle.kts.

plugins {
   kotlin("kapt") version "1.3.72"
}

dependencies {   
   kapt("org.mapstruct:mapstruct-processor:1.3.1.Final")
}

#dto #kotlin #spring-boot #mapstruct

Sigrid  Farrell

Sigrid Farrell

1624141200

Avoiding Code Duplication by Adding an API Layer in Spring Boot

Using back-end HTTP clients to build an advanced API Layer

Your back-end may need to make numerous synchronous or asynchronous requests to many different web services to retrieve or write data. In particular, the common way for back-ends to communicate with each other in a microservice architecture is through the HTTP protocol.

In order to avoid code duplication, I am going to show how to design a specific layer dedicated to the handling of external requests where you can place the definitions of all the needed API requests. This layer aims to divide where API requests are defined from where they are used to make calls.

In this tutorial, I am going to use RestTemplate, but any other HTTP client can be employed as well.

Code snippets will be written in Spring Boot and Kotlin, but this approach can easily be adapted to any other frameworks, libraries, or programming language.

Please note that the same concept can be applied in front-ends as I showed in this article.

Let’s see how this can be accomplished in just a few steps.

#software-engineering #software-design #spring-boot #avoiding code duplication by adding an api layer in spring boot #api #avoiding code duplication

Were  Joyce

Were Joyce

1620751200

How to Configure the Interceptor With Spring Boot Application

In the video in this article, we take a closer look at how to configure the interceptor with the Spring Boot application! Let’s take a look!

#spring boot #spring boot tutorial #interceptor #interceptors #spring boot interceptor #spring boot tutorial for beginners

Were  Joyce

Were Joyce

1620720872

Spring vs Spring BooDifference Between Spring and Spring Boot

As an extension of the Spring Framework, Spring Boot is widely used to make development on Spring faster, more efficient and convenient. In this article, we will look at some of the parameters were using Spring Boot can drastically reduce the time and effort required in application development.

What is Spring?

Spring Boot

Difference between Spring and Spring Boot

Advantages of Spring Boot over Spring

Conclusion

#full stack development #spring #spring and spring boot #spring boot

Artem Diashkin

Artem Diashkin

1618853516

Spring Boot With Kotlin. Create a Project With a HTML Page and API Endpoints in Examples

Here we will take a look at how we can create a simple Spring Boot application in a few seconds using Spring initializr, how we can create a simple HTML page and API Endpoints.

https://medium.com/litslink/spring-boot-with-kotlin-create-a-project-with-a-simple-html-page-and-api-endpoints-in-examples-17d905c0b711

#java #spring #spring-framework #spring-boot #kotlin