Hey guys, I was waiting for 1.0.0, nice work :slig...
# serialization
d
Hey guys, I was waiting for 1.0.0, nice work 🙂 I wonder if kotlinx.serialization can be easily be used for converting collection types to actual objects and vice-versa without actually serializing. Or iterate the fields of an object.
I have a ORM library ( https://github.com/korlibs/kminiorm ) that currently only works on the JVM because it uses reflection to convert objects into maps, lists and primitives and would want to make it multiplatform
If that's possible, can you help me pointing to the right documentation to do this?
c
I think it should be possible in theory, assuming you have the platform-specific SQL drivers to talk to. Given a
KSerializer
, you’d need to write a custom
Encoder
to pass into that KSerializer. The generated kotlinx.serialization code should write into your Encoder the proper structures with field names and values, nested collections, nested objects, etc. Your Encoder would accept those values to build the SQL queries There are some docs for writing custom formats, which would probably be a good place to start https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/formats.md#custom-formats-experimental
Looking at some of the default implementations is probably your best bet for actually figuring out how to write all this. The Properties format seems very simple and straightforward to follow to start with https://github.com/Kotlin/kotlinx.serialization/blob/master/formats/properties/commonMain/src/kotlinx/serialization/properties/Properties.kt
d
Cool. Thanks for the pointers!