instead of Json format: ```val obj = Json.decodeFr...
# serialization
d
instead of Json format:
Copy code
val obj = Json.decodeFromString<Data>("""{"a":42, "b": "str"}""")
is there a way to decode key/value pairs concatenated by
&
?
Copy code
a=42&b=str
or should I convert my key/value pairs into Json?
e
depends on how you want to handle various cases - like how shoud nested members work - but a little bit of preprocessing and it might work with https://github.com/Kotlin/kotlinx.serialization/blob/master/formats/properties/commonMain/src/kotlinx/serialization/properties/Properties.kt
Copy code
Properties.decodeFromMap(
    str.splitToSequence('&').associate {
        val (k, v) = it.split('=', limit = 2)
        k to v
    }
)
Properties.encodeToMap(obj).entries.joinToString("&") { (k, v) -> "$k=$v" }
d
thanks! yes, I don’t need to care about nesting, they are all primitive types
d
Hmmm, are you using this for URLs? Ktor has a proof of concept PR for this, if that's the case.
e
and I'm sure it will handle urlencoding where needed (where my code above doesn't at all)
d
thanks, I will have a look