kotlinx.serialization v1.2.0 Release Notes

Release Date: 2021-04-27 // 3 months 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).