how to parse a json string into data class?
# getting-started
c
how to parse a json string into data class?
b
You can do it like this. https://stackoverflow.com/a/48761937
👍 1
👎 2
j
Actually you shouldn't use Gson for multiple reasons. It's in maintenance mode, it's not adapted to Kotlin features (it's a java library), and it's reflection-based. If you want to use a library that works like Gson, you should instead use its successor Moshi. But the idiomatic Kotlin library is kotlinx.serialization. You should use this in most cases: https://github.com/Kotlin/kotlinx.serialization
👍 2
👍🏽 1
c
Thanks. I will update that part.
p
@Joffrey I have always wondered. Is there a specific reason that
kotlinx.serialization
does not support xml?
j
It does. It decouples the formats from the serialization déclaration. There are a few formats that are built-in, and indeed XML isn't built-in, but there is a third-party XML format for it which works great.
gratitude thank you 1