Yummypets / JSON.kt

Kotlin JSON Parsing that infers type (org.json.JSONObject Wrapper)
MIT License
8 stars 1 forks source link

Pure Kotlin implementation and dependencies #1

Open remysanfeliu opened 5 years ago

remysanfeliu commented 5 years ago

Hi ! Love your syntax and the way the code looks :) Great job ! I'm working on a multiplatform Kotlin project though, and thus can't rely on org.json as it's written for java. It would be great if you could get rid of this dependency to be actually fully Kotlin based !

Just a suggestion for future releases !

s4cha commented 5 years ago

Hi @remysanfeliu, thanks for the kind words! Actually I am quite new to the Kotlin ecosystem and have only used it on Android so far. Could you elaborate one how you'd go about parsing JSON without depending on java libraries? Thanks a ton :)

remysanfeliu commented 5 years ago

The idea is to remove any import and dependency on JVM-based libraries ideally, so that the parser is pure Kotlin code, end to end, including deps. org.json is coded with Java, so that's that :D My suggestion is to use kotlinx.serialization instead to parse the JSON, which is guaranteed to support Kotlin multiplatform. Although, it might be a difficult task because it only seems to be supporting parsing via annotations, and not "manual" browsing which might be useful for your lib (don't know, actually). BTW, don't turn to Klaxon, it's actually based on some java.Class here and there to match types, so, it seems that it couldn't fit a multiplatform project =/ (I need to check this though, will be back in a few days with a confirmation)

s4cha commented 5 years ago

@remysanfeliu Thanks for your answer. We deliberately don't want to use annotations as you pointed out. They pollute the model and in my opinion, they violate the Single Responsibility Principle. (I personally avoid them like the plague xD) Klaxon is not an option in that sense :) I agree that being "java free" is a very appealing idea. However, this project is just a helper we did to clean our parsing code and are not willing to spend too much time in such endeavour. Additionally,kotlinx.serialization seems to be the way to go forward for Kotlin-pure implementations.

Feel free to try on your own of course, and if you have anything cool I'd bee very curious to see the result :) Cheers,