New Serialization Library for Kotlin

One point about the Kotlin serialization plugin. People seem to equate the formats built in to the library with the capability of the system. It is perfectly possible to write your own formats or to even create ones that do JSON… in a different way, perhaps delegating to the original where appropriate. For example, the caching feature is something that can be perfectly supported by a format.

The serialization plugin basically creates the code specific to the type to be serialized. The format gets the right callbacks and does the serialization. (I’ve written a format for XML). I would have to say that the current format is somewhat cumbersome and seriously underdocumented. The new proposed version in the KEEP is much better. The plugin can also have features that are hard to implement otherwise or much less elegant (like default values).

As an alternative for a when Java objects need to be handled, have a look at Kryo that also supports custom adapters. It can be made Kotlin compatible quite easily (you need to special-case Kotlin objects to retain single instances). It serialises literally anything, but does use reflection.