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

Romão

08/03/2022, 9:13 PM
I'm learning Android development, trying to do code a simple app. Want to load a JSON file on the assets folder into a string in ViewModel (livedata). Can someone point correct way to load the JSON data (user, id:Int + name:String), shall i use GSON (looks its "old), Moshi (newer) or something else?
j

Joffrey

08/03/2022, 9:16 PM
I'd suggest kotlinx serialization or Moshi, not Gson
👍 2
l

Landry Norris

08/03/2022, 9:21 PM
kotlinx.serialization has worked well for me so far. It’s also multiplatform if you ever decide to go that route.
a

Andrew O'Hara

08/03/2022, 9:30 PM
The main reason you might want to avoid Gson -- in kotlin specifically -- is that it isn't null safe. It will happily put a null in your non-null properties, which will crash as soon as you try to access them.
2 Views