![Kotlin serializable data class](https://cdn3.cdnme.se/5447227/9-3/1_64e61dfaddf2b33c615a3cd3.png)
![kotlin serializable data class kotlin serializable data class](https://i.stack.imgur.com/mh6DJ.jpg)
On iOs the equivalent to Retrofit is Alamofire. create(ActivityApiService :: class.java) addConverterFactory(Json.asConverterFactory(MediaType.
![kotlin serializable data class kotlin serializable data class](https://codersguidebook.com/how-to-create-an-android-app/images/new-kotlin-class.png)
API #įor this example I will use the Bored Api that returns this kind of response: And for the deserialization, I will use (of course) the Kotlin Serialization library. In this article, I will show you how to implement a Kotlin Multiplatform Mobile application that performs a network call on the native side with Retrofit (on Android) and Alamofire (on iOs) but the DTOs are defined on KMP side as well as the information about deserialization. But how to start using KMP in an existing project, is a topic for another article, so stay tuned! Because in this way we can define a single source of truth and share it on the backend and the mobile clients. We decided to start integrating KMP and we thought that the perfect target to start with is the DTOs. Maybe you are starting to integrate Kotlin Multiplatform (I’ll call it KMP in the rest of the article) into an existing project and the work for sharing the entire network layer is simply too much.Īnd this was the case for the project that I’m working on. There could be many reasons for wanting this. But if you don’t want to share the entire network layer but maybe only the DTOs? If you are starting a project with Kotlin Multiplatform and you want to share the network layer, the best way to go is definitely with Ktor.
![Kotlin serializable data class](https://cdn3.cdnme.se/5447227/9-3/1_64e61dfaddf2b33c615a3cd3.png)