Might be a silly question, but I need to serialize...
# serialization
z
Might be a silly question, but I need to serialize
Map<String, String>
into a file, and deserialize it back into
Map<String, String>
. Does kotlin serialization have a preferred/convenient way to do this?
e
pick whatever format you like,
Copy code
val input: Map<String, String> = mapOf(...)
file.writeText(Json.encodeToString(input))
val output: Map<String, String> = Json.decodeFromString(file.readText())
Copy code
file.writeBytes(Cbor.encodeToByteArray(input))
val output: Map<String, String> = Cbor.decodeFromByteArray(file.readBytes())
❤️ 1