1

is there any solution other than Moshi, Gson, KotlinX-Serialization to serialize json in Android? We should not add anything to build.gradle while using technology. We should not download a library from here.

Is there a method on Android just like Codable on iOS? Also, I think how we should do this part is important since Converter will be passed when using it with Retrofit.

Does anyone have experience and advice on this subject?

enjektor0
  • 483
  • 2
  • 8
  • 1
    Well... all of those libs are open source you can always [look at their source code](https://github.com/Kotlin/kotlinx.serialization). In Android there's the implementation of JSON objects in the `org.json` package which, if I am not mistaken, comes with the framework. You'd have to do the parsing yourself, just like with Codable on iOS. If you want samples, there [are](https://stackoverflow.com/a/12738097/2684) [plenty](https://stackoverflow.com/a/10674182/2684) of examples. – Martin Marconcini Feb 08 '22 at 12:00
  • Why not use a third party? You aren't allowed to use any third party? You know `RetroFit` is a third party too right? – Ivo Feb 08 '22 at 12:05
  • I'm building an android library and I don't want to use a third party library. I guess we won't be using retrofit either. – enjektor0 Feb 08 '22 at 12:32

1 Answers1

1

You can use JSONObject for that.

val json = JSONObject("""{"some":"json"}""")

However, easiest is to use one of the third party frameworks you mentioned to do this.

Stephan
  • 15,704
  • 7
  • 48
  • 63