1

I want to convert a list of a model that I've defined to String for saving it in Database I know how to do that in Gson but I want to do the same in kotlinx.serialization

Convert a list of a model to String In Gson:

val gson = Gson()
return gson.toJson(data)

Convert the String to the model in Gson:

val listType = object : TypeToken<ArrayList<String>>() {}.type
return Gson().fromJson(string, listType)

How can I do that in kotlinx.serialization?

Arsham
  • 11
  • 2
  • 3
    It's documented in the kotlix.serialization [docs](https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/builtin-classes.md#lists) – Pavel Jan 01 '23 at 05:37
  • And note that's not all the documentation, which is extensive: [Kotlin Serialization Guide](https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serialization-guide.md). – Slaw Jan 01 '23 at 06:31

0 Answers0