Kotlinx.serialization and custom encoders/decoders

Is there any documentation on writing custom encoders and decoders for kotlinx.serialization?

Also, how stable is the API? What is the chance that an encoder and decoder written today would need a major rewrite before the API is finalized?

Have a look here GitHub - Kotlin/kotlinx.serialization: Kotlin multiplatform / multi-format serialization

I had problems trying to do this a few weeks back, and gave up. I’m curious what kind of custom serializer you want to write, and if you will be able to do it. Good luck.

I use Yaml custom serializer and works.

I guess I’m confused on the vocab. He asked about encoders and decoders, and I thought he meant serializers, but I guess that really means formats, like Json, CBOR, Yaml, etc. In which case, I should shut up, because I tried to write a custom serializer, not a custom format like Yaml.

Yes, it’s a custom format I’m trying to serialize to/from. I was confused about the terminology as well, but the KEEP helped clarify things a bit.

It sounds like the closest thing to documentation that exists at the moment are the existing Encoder/Decoder implementations.

Hi @xenomachina,

There isn’t really much documentation. I did my own one for XML. Due to the requirements of XML (and my wishes for the serializer) that was far from trivial. Overall however doing so helped the API improve. There were some major changes that needed to be incorporated (even if they were for the best).

Have a look at the existing ones. You could take a look at mine: GitHub - pdvrieze/xmlutil: XML Serialization library for Kotlin but it is not a simple one due to needing to support things like missing elements, out of order attributes, etc.

If you have any questions, I’d be happy to answer them.