kotlinx.serialization v1.2.0 Release Notes

Release Date: 2021-04-27 // almost 3 years ago
  • ๐Ÿš‘ This release has some known critical bugs, so we advise to use 1.2.1 instead.

    ๐Ÿš€ This release contains a lot of new features and important improvements listed below; 0๏ธโƒฃ Kotlin 1.5.0 is used as a default compiler and language version.

    ๐ŸŽ JSON performance improvements

    JSON encoder and decoder were revisited and significantly rewritten, which lead us to up to 2-3x times speedup in certain cases. โž• Additional details can be found in the corresponding issues: [1], [2].

    Ability to specify alternative names during JSON decoding

    ๐Ÿ›  The one of the most voted issues is fixed now โ€” it is possible to specify multiple names for one property using new @JsonNames annotation. Unlike @SerialName, it only affects JSON decoding, so it is useful when dealing with different versions of the API. ๐Ÿ“š We've prepared a documentation for you about it.

    JsonConfiguration in public API

    JsonConfiguration is exposed as a property of Json instance. You can use it to adjust behavior in ๐Ÿ“„ your custom serializers. Check out more in the corresponding issue and the PR.

    Generator for .proto files based on serializable Kotlin classes

    Our implementation of Protocol Buffers format uses @Serializable Kotlin classes as a source of schema. This is very convenient for Kotlin-to-Kotlin communication, but makes interoperability between languages complicated. To resolve this issue, we now have a schema generator that can produce .proto files out of Kotlin classes. Using it, you can keep Kotlin classes as a source of truth and use traditional protoc compilers for other languages at the same time. ๐Ÿ“š To learn more, check out the documentation for the new ProtoBufSchemaGenerator class or visit the corresponding PR.

    Note: this generator is on its experimental stage and any feedback is very welcomed.

    Contextual serialization of generic classes

    Before 1.2.0, it was impossible to register context serializer for generic class, because contextual function accepted a single serializer. Now it is possible to register a provider โ€” lambda that allows to construct a serializer for generic class ๐Ÿ“š out of its type arguments serializers. See the details in the documentation.

    Other features

    • Support for watchosX64 target (#1366).
    • Introduce kotlinx-serialization-bom (#1356).
    • Support serializer on JS IR when T is an interface (#1431).

    ๐Ÿ›  Bugfixes

    • Fix serializer lookup by KType for third party classes (#1397) (thanks to mvdbos).
    • Fix inability to encode/decode inline class with string to JsonElement (#1408).
    • Throw SerializationException instead of AIOB in ProtoBuf (#1373).
    • Fix numeric overflow in JsonLexer (#1367) (thanks to EdwarDDay).