Kotlin multiplatform / multi-format serialization
This release provides a couple of new features and uses Kotlin 1.9.22 as default.
Class discriminator provides information for serializing and deserializing polymorphic class hierarchies.
In case you want to encode more or less information for various third party APIs about types in the output, it is possible to control
addition of the class discriminator with the JsonBuilder.classDiscriminatorMode
property.
For example, ClassDiscriminatorMode.NONE
does not add class discriminator at all, in case the receiving party is not interested in Kotlin types.
You can learn more about this feature in the documentation and corresponding PR.
This is a patch release accompanying Kotlin 1.9.21. It also provides additional targets that were not available in 1.6.1: wasm-wasi
and (deprecated) linuxArm32Hfp
.
This release uses Kotlin 1.9.20 by default, while upcoming 1.9.21 is also supported.
Trailing commas are one of the most popular non-spec Json variations. A new configuration flag, allowTrailingComma
, makes Json parser accept them instead of throwing an exception. Note that it does not affect encoding, so kotlinx.serialization always produces Json without trailing commas. See details in the corresponding PR.
Kotlin/Wasm has been experimental for some time and gained enough maturity to be added to the kotlinx libraries. Starting with 1.6.1, kotlinx.serialization provides a wasm-js flavor, so your projects with Kotlin/Wasm can have even more functionality. As usual, just add serialization dependencies to your build and declare wasmJs target. Please remember that Kotlin/Wasm is still experimental, so changes are expected.
@ByteString
(#2466) (thanks to eater)This release contains all features and bugfixes from 1.6.0-RC plus some bugfixes on its own (see below). Kotlin 1.9.0 is used as a default, while 1.9.10 is also supported.
@SerialName
, @Required
and @Transient
with @MustBeDocumented
(#2407)This release is based on the Kotlin 1.9.0.
Some time ago, in Kotlin 1.8, JS IR compiler was promoted to stable and old JS compiler was deprecated. Kotlin 1.9 promotes the usage of deprecated JS compiler to an error. As a result, kotlinx.serialization no longer builds with the legacy compiler and does not distribute artifacts for it. You can read the migration guide for JS IR compiler here.
Also pay attention to the fact that Kotlin/Native also has some deprecated targets that are going to be removed in the Kotlin 1.9.20. Therefore, kotlinx.serialization 1.6.0-RC and 1.6.0 are likely the last releases that support these targets.
This release features a new configuration flag for Json: decodeEnumsCaseInsensitive
that allows you to decode enum values in a case-insensitive manner.
For example, when decoding enum class Foo { VALUE_A , VALUE_B}
both inputs "value_a"
and "value_A"
will yield Foo.VALUE_A
. You can read more about this feature in the documentation and corresponding PR.
This release contains an important Native targets overhaul, as well as numerous enhancements and bugfixes. Kotlin 1.8.21 is used by default.
The official Kotlin target support policy has recently been published describing new target policy: each target belongs to a certain tier, and different tiers have different stability guarantees. The official recommendation for library authors is to support targets up to Tier 3, and kotlinx.serialization now follows it. It means that in this release, there are a lot of new targets added from this tier, such as androidNativeX86
or watchosDeviceArm64
. Note that since they belong to Tier 3, they're not auto-tested on CI.
kotlinx.serialization also ships some deprecated Kotlin/Native targets that do not belong to any tier (e.g. iosArm32
, mingwX86
).
We'll continue to release them, but we do not provide support for them, nor do we plan to add new targets from the deprecated list.
There are two new function sets that should make creating raw Json elements easier.
First one contains overloads for JsonPrimitive
constructor-like function that accept unsigned types: JsonPrimitive(1u)
.
Second one adds new addAll
functions to JsonArrayBuilder
to be used with collections of numbers, booleans or strings: buildJsonArray { addAll(listOf(1, 2, 3)) }
.
Both were contributed to us by aSemy.
target
variables to sink
(#2226)This release contains all features and bugfixes from 1.5.0-RC plus some experimental features and bugfixes on its own (see below). Kotlin 1.8.10 is used as a default.
These interfaces work in a way similar to JsonEncoder
and JsonDecoder
: they allow intercepting (de)serialization process,
making writing if custom HOCON-specific serializers easier. New ConfigMemorySizeSerializer
and JavaDurationSerializer
already make use of them.
See more details in the PR.
Big thanks to Alexander Mikhailov for contributing this!
New interface ChunkedDecoder
allows you to read huge strings that may not fit in memory by chunks.
Currently, this interface is only implemented by Json decoder that works with strings and streams,
but we may expand it later, if there's a demand for it.
See more details in the PR authored by Alexey Sviridov.
This is a release candidate for the next version with many new features to try. It uses Kotlin 1.8.0 by default.
A long-awaited feature (#33) is available in this release.
A new interface, JsonNamingStrategy
and Json configuration property namingStrategy
allow
defining a transformation that is applied to all properties' names serialized by a Json instance.
There's also a predefined implementation for the most common use case: Json { namingStrategy = JsonNamingStrategy.SnakeCase }
.
Check out the PR for more details and documentation.
kotlinx-serialization-json has an API for manipulating raw Json values: functions and classes JsonObject
, JsonPrimitive
, etc.
In this release, there is a new addition to this API: JsonUnquotedLiteral
constructor function.
It allows to produce a string that is not quoted in the Json output. This function has a lot of valuable
applications: from writing unsigned or large numbers to embedding whole Json documents without the need for re-parsing.
For an example, read the Encoding literal Json content docs.
This huge feature was contributed to us by aSemy: #2041.
Functions serializer
, serializerOrNull
and extensions SerializersModule.serializer
, SerializersModule.serializerOrNull
have JVM-only overloads that accept java.lang.Type
. These overloads are crucial for interoperability: with them, third-party Java frameworks
like Spring, which usually rely on Java's reflection and type tokens, can retrieve KSerializer
instance and use kotlinx.serialization properly.
We've removed @ExperimentalSerializationApi
from these functions, and starting from 1.5.0-RC they're considered stable with all backward compatibility guarantees.
This change should improve third-party support for kotlinx.serialization in various frameworks.
See the PR for details.
Some time ago, in 1.3.2, new functions SerializersModuleBuilder.polymorphicDefaultSerializer/polymorphicDefaultDeserializer
and PolymorphicModuleBuilder.defaultDeserializer
were introduced
— better names allow an easier understanding of which serializers affect what part of the process.
In 1.5.0-RC, we finish the migration path: these functions are no longer experimental.
And old functions, namely SerializersModuleCollector.polymorphicDefault
and PolymorphicModuleBuilder.default
, are now deprecated.
See the PR for details.
The kotlinx-serialization-core-jvm
JAR file now includes consumer Proguard rules,
so manual Proguard configuration is no longer necessary for most of the setups.
See updated Android setup section and corresponding PRs: #2092, #2123.
HOCON specifies its own formatting for duration values. Starting with this release,
kotlinx-serialization-hocon is able to serialize and deserialize kotlin.Duration
using proper representation instead of the default one. Big thanks to Alexander Mikhailov
and his PRs: #2080, #2073.
kotlin.Nothing
class as built-in (#1991, #2150)This patch release contains several bug fixes and improvements. Kotlin 1.7.20 is used by default.
This release contains all features and bugfixes from 1.4.0-RC plus some bugfixes on its own (see below). Kotlin 1.7.10 is used as a default.