7

My resialized is "{"2":"Hello","Tesst":"Value"}"

I tried to parse this string to Map<String,String>

            val resialized = readFile(createStorageDirectoryPath(getManifestFilePath()), MANIFEST_FILE_NAME, errorOut)
                manifest = Json.decodeFromString(/*serializer*/, resialized)

How I create a serializer for Map<String,String>

1 Answer 1

13

You can use an other version of decodeFromString which will take care of deserializer by itself.

import kotlinx.serialization.decodeFromString

val res = Json.decodeFromString<Map<String, String>>("{\"2\":\"Hello\",\"Tesst\":\"Value\"}")

It's marked with ExperimentalSerializationApi, but I had no problems using it for the last year. This method is recommended by documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.