https://kotlinlang.org logo
#getting-started
Title
# getting-started
c

Colton Idle

04/20/2022, 6:37 AM
I currently have an object that prints out as such
Country(code=AD, name=Andorra)
but I need to convert it into json. Is there a stringify method or something I can use from kotlin stdlib in android? Most questions I look up on stackoverflow want me to bring in gson, but I really dont want to bring in a depedency for just this single little manipulation. Am I missing something basic here?
t

Tolriq

04/20/2022, 6:39 AM
If you bring something bring Moshi 🙂 You can use the plain JSONObject too, or use kotlinx serialization. But there's no magic to talk json you need something that talk json and there's nothing in stb lib.
c

Colton Idle

04/20/2022, 6:41 AM
Hm. I can use JSONObject but its not part of stdlib?
i guess that comes from android itself?
t

Tolriq

04/20/2022, 6:57 AM
Yes
👍 1
p

pitpit

04/20/2022, 7:03 AM
You can use kotlin serialization : https://github.com/Kotlin/kotlinx.serialization
👍 4
2 Views