I have a simple app that makes a simple network re...
# getting-started
c
I have a simple app that makes a simple network request to get json. How do I convert that into an object without any 3rd party deps? I typically use gson or moshi for this sort of thing, but I don't think it's worth bringing in an entire library for this single network call. I know in java we used to just use some really bad Json apis, but I wonder if kotlin has anything else out of the box.
c
I've also heard of kotlinx.serialization, but I thought it was "similar" to moshi/gson where it's an additional library.
h
It is, but I dont think, you want parse Json manually? So you would need some library, and Kotlinx serializiation does not use reflection at runtime, but a compiler plugin at compile time. BTW Gson is dead.
c
yeah. like i said. I typically use moshi, but bringing in a library for it seemed crazy, just to map like 4 fields in a data class. I'll try kotlinx.serialization. If anyone else has another suggestion. Let me know. Thanks!
m
but bringing in a library for it seemed crazy, just to map like 4 fields in a data class
best wishes writing your JSON parser 😉
jokes aside, for a simple case like this maybe you just need a parser and then do manual binding to your domain type, so you can shrink dependencies. But anyway, kotlinx.serialization is your best choice
c
thanks. I've used org.json when I needed a quick object in my java android code, so I was wondering if there was anything like that, but it sounds like kotlinx it is!
👍 1
t
it depends, I still think it depends on your target. if jvm, jackson or gson are still less pain than kotlinx serialization, but if you want to target also js or ios, then kotlinx