11/11/2023 0 Comments Kotlin null default value![]() To my knowledge, to make use of the described Kotlin features like null-safety and default arguments, all libraries supporting Kotlin fully use kotlin-reflect, which is around 2MB in size and therefore might not be an option.We don’t want to use android’s org.json, because it has very limited capabilities and no mapping functionality at all. ![]() ![]() On android, we also want a small APK size, so a reduced number of dependencies and small libraries. We also want near zero overhead automatic mapping from JSON to objects and in reverse. We also would probably want explicit exceptions when the mapping fails completely (required field missing). What the challenge of using Kotlin and JSON boils down to is: We want to use Kotlin data classes for concise code, non-nullable types for null-safety and default arguments for the data class constructor to work when a field is missing in a given JSON. The author uses Moshi, which has easy to use Kotlin support. Then, there are multiple articles like this one, talking about how to handle Kotlin data classes with json. First of, there is the Awesome-Kotlin list about JSON libraries. There are already multiple articles and sources about using Kotlin and JSON. Most elegant way of using Gson + Kotlin with default values and null safety
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |