v1.2.0
版本发布时间: 2021-04-29 00:32:36
Kotlin/kotlinx.serialization最新发布版本:v1.7.2(2024-08-29 01:45:05)
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; 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 pull requests: [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<T> on JS IR when T is an interface (#1431).