Migrate the serialization from Klaxon to kotlinx-serialization library
This will help integrate the dataframe better into other libraries where serialization is required, such as ktor, ggdsl, and others
Didn't @belovrv have concerns about that?
@belovrv had doubts about the performance of kotlinx.serialization. We discussed this issue and came to the conclusion that there are no obvious problems. However, since this task is quite time-consuming, even though part of the serialization/deserialization logic will be preserved from Klaxon, we decided to postpone its implementation
I'd like the serialization and io tasks and especially both libraries, klaxon and kotlinx.serialization, will assign it to me
A bit more detail about serialization support.
Benefits:
-
Performance. Based on my limited research, simple conversion to strings is performance-wise equivalent to
klaxon, as it performs identical logic. Marking classes as serializable and writing custom serializers, the performance ofkotlinx-serializationis expected to be higher thanklaxon. However, the actual implementation of the serializers will also affect this. In general, the performance will be slightly better or the same as klaxon. Thus, I wouldn't consider this as the main reason for switching tokotlinx-serializationor for sticking withklaxon. -
Code Refactoring. Support for
kotlinx-serializationwill help us improve the code responsible for json parsing. When I examined the code, I found some code quality issues. Serializers for dataframe will help alleviate this area, which will increase the codebase but will improve code readability and quality. -
Type Inference. This will affect type parsing, as some of the load can be shifted to the
kotlinx-serializationplugin. This, in turn, will help us partially eliminate the use of platform-dependent reflection. Also, kotlinx-serialization has better support forJsonElement. For example, it can identifyNaNunlike klaxon. -
Kotlin Ecosystem.
kotlinx-serializationis an official library and is part of the Kotlin ecosystem, which will make it easier for us to work within it in the future. For example, withKtor. There are also guarantees that it will be supported further. -
Other Formats. While official support is limited, interestingly, there is support for
Protobuf. - Multiplatform Support. kotlinx-serialization is a multiplatform library.
-
Flexibility and reliability. Writing custom serializers will allow better control over serialization and deserialization. For example, this can help avoid issues with serialization when a
Mapmight be inside a column.
I envision the migration from klaxon to kotlinx-serialization as follows:
- To start, we can simply get rid of klaxon by switching
JsonElementfrom klaxon toJsonElementfromkotlinx-serialization. Since the logic is identical, this won't be too difficult. It will only be necessary to consider thatkotlinx-serializationhasJsonPrimitive, unlikeklaxon. AndjsonObjectBuilderlooks a bit different. - This is a more complex part that can be broken down into several steps:
- The
JSONobject and transformation related to the schema — https://kotlin.github.io/dataframe/read.html#specify-key-value-paths It will be necessary to analyze how to improve this part or keep the simple parsing of the json tree. - Separating serialization and deserialization. Break down for specific objects, such as
DataFrame,DataColumn. - Identifying necessary objects that are used when working with json. Since working with open interfaces is challenging.
- Writing custom serializers for classes
@devcrocod could we say that this is our blocker to be multiplatform?
@zaleslaw Just one of many: https://github.com/Kotlin/dataframe/issues/24#issuecomment-1958239332