iumose.blogg.se

Android kotlin serialization
Android kotlin serialization












android kotlin serialization

We were never really sure about our strategy to share our API models with our clients would really work not because it was a bad idea but because we knew it would be difficult to get buy in from our API developers. Also note that it’s kapt(“…”) not implementation(“…”).Continuing on our journey from the article “ The first steps on your Kotlin Multiplatform journey - changing your microservices” that I wrote last year, I wanted to give an update on our progress and share some learnings. Please note that kapt needs to come after the jvm plugin. For our purposes we install a ContentNegotiation feature like so: install(ContentNegotiation) kapt(":moshi-kotlin-codegen:1.12.0")

android kotlin serialization

(in other frameworks a feature would be called middleware, filter or delegate handler)Ī feature can be installed using the install function. They are just another Ktor Feature like routing, logging or error handling:

android kotlin serialization

IntermezzoĬustom converters can be registered with Ktor easily. The deserialization part created an account first then a customer referencing that account -> POST. The serialization part retrieved a list of customers (ArrayList), each one referencing an account -> GET. I wanted to serialize/deserialize this data structure(s): data class Customer( var customerUUID: String, var createdAt: Instant, var modified: Instant, var firstName: String, var lastName: String, var language: Language, var account: Account, ) data class Account( var accountUUID: String, var createdAt: Instant, var modified: Instant, var status: AccountStatus ) I left out Jackson because… well why not -). I tested #1 and #3 and because I like challenges from time to time I threw Moshi into the mix.

android kotlin serialization

As part of my series “ An opinionated Kotlin backend service”, I was checking out different ways to serialize/deserialize JSON payloads.Īccording to these are the supported converters:














Android kotlin serialization