Kotlinx Serialization Mapper
Introduction
Built on top of the famous kotlinx-serialization-json
, this library helps to serialize between json maps and kotlin maps.
Samples
Getting an map from a json
val json = """
{
"environment": "production",
"logging": "warnings",
"key": "SOME_TEST_KEY",
"bool": true,
"integer": 43,
"double": 46.55
}
""".trimIndent()
val map = Mapper.decodeFromString(json)
val environment: String by map
val logging: String by map
val key: String by map
val bool: Boolean by map
val integer: Int by map
val double: Double by map
Setup:Gradle
Adding kotlinx-serialization-mapper
as a dependency becomes as easy as just
Kotlin Multiplatform
kotlin {
// . . .
sourceSets {
val commonTest by getting {
dependencies {
implementation("tz.co.asoft:kotlinx-serialization-mapper:+") // please use the latest version possible
}
}
}
}
Kotlin [android|jvm|js]
kotlin {
// . . .
dependencies {
implementationTest("tz.co.asoft:kotlinx-serialization-mapper:+") // please use the latest version possible
/* Or
* You can be as specific as
* "tz.co.asoft:kotlinx-serialization-mapper-android:+"
* "tz.co.asoft:kotlinx-serialization-mapper-jvm:+"
* "tz.co.asoft:kotlinx-serialization-mapper-js:+"
*/
implementationTest("tz.co.asoft:kotlinx-serialization-mapper-android:+") // please use the latest version possible
}
}