kotlinx.serialization

Kotlin multiplatform / multi-format serialization

APACHE-2.0 License

Downloads
28
Stars
5.1K
Committers
181

Bot releases are hidden (Show)

kotlinx.serialization - 1.7.1 Latest Release

Published by sandwwraith 4 months ago

This is a bugfix release that aims to fix missing kotlinx-serialization-hocon artifact.
It also contains experimental integration with kotlinx-io library.
Kotlin 2.0.0 is used by default.

Fixed HOCON publication

Sadly, 1.7.0 release was published incomplete: kotlinx-serialization-hocon artifact is missing from 1.7.0 and 1.7.0-RC releases.
This release fixes this problem and now kotlinx-serialization-hocon is available again with 1.7.1 version.
No other changes were made to this artifact. Related ticket: #2717.

Add integration with a kotlinx-io library

kotlinx-io is an official multiplatform library that provides basic IO primitives, similar to Okio.
kotlinx.serialization integration is now available in a separate artifact, located at the kotlinx-serialization-json-io coordinates. Integration artifact provides functions similar to existing Okio integration: encodeToSink, decodeFromSource, and decodeSourceToSequence. Check out the PR for more details.

Other bugfixes

  • Prohibited use of elements other than JsonObject in JsonTransformingSerializer with polymorphic serialization (#2715)
kotlinx.serialization - 1.7.0

Published by sandwwraith 4 months ago

This release contains all of the changes from 1.7.0-RC and is compatible with Kotlin 2.0.
Please note that for reasons explained in the 1.7.0-RC changelog, it may not be possible to use it with the Kotlin 1.9.x
compiler plugin. Yet, it is still fully backward compatible with previous versions.

The only difference with 1.7.0-RC is that the classDiscriminatorMode property in JsonBuilder is marked as experimental,
as it should have been when it was introduced (#2680).

kotlinx.serialization - 1.7.0-RC

Published by sandwwraith 5 months ago

This is a release candidate for the next version. It is based on Kotlin 2.0.0-RC3 and is fully compatible with a stable Kotlin 2.0 release.
Due to a potential breaking change (see below), it requires a compiler plugin with a version at least of 2.0.0-RC1.

Important change: priority of PolymorphicSerializer for interfaces during call to serializer() function

Non-sealed interfaces in kotlinx.serialization are always serializable with a polymorphic serializer,
even if they do not have @Serializable annotation. This also means that serializersModule.serializer<SomeInterface>() call will return you a serializer capable of polymorphism. This function was written in a way that it unconditionally returns a PolymorphicSerializer if type argument is a non-sealed interface. This caused problems with SerializersModule functionality, because actual module was not taken into consideration, and therefore it was impossible to override serializer for interface using 'contextual serialization' feature. The problem is described in detail here. To overcome these problems, we had to change the behavior of this function regarding interfaces. It now looks into SerializersModule first if T is a non-sealed interface, and only if there is no registered contextual serializer for T, it returns a polymorphic serializer.

Behavior before 1.7.0-RC:

interface SomeInterface

val module = SerializersModule {
    contextual(SomeInterface::class, CustomSomeInterfaceSerializer)
}

// Prints PolymorphicSerializer<SomeInterface>:
println(module.serializer<SomeInterface>())

Behavior in 1.7.0-RC, 1.7.0, and higher:

interface SomeInterface

val module = SerializersModule {
    contextual(SomeInterface::class, CustomSomeInterfaceSerializer)
}

// Prints CustomSomeInterfaceSerializer:
println(module.serializer<SomeInterface>())

We expect minimal impact from this change, but be aware of it anyway.
Implementation details are available in this PR.

Due to the serializer() function being also a compiler intrinsic, code
of kotlinx.serialization compiler plugin also accommodates this change in the 2.0 branch. To get a consistent result from both plugin and runtime, kotlinx.serialization compiler plugin should be at least of 2.0.0-RC1 version.
To verify so, 1.7.0-RC runtime will be rejected by older plugins.

Json configuration flag to allow commentaries

While JSON standard does not allow any kind of commentaries, they are one of the most popular extensions — for example, commentaries are widely used in configuration files. To support this use-case, we added a new configuration flag, allowComments. This flag allows the parser to skip over C/Java-style commentaries in JSON input. Note that commentaries cannot affect decoding or encoding in any way and are not stored anywhere. See details in the PR.

Promote JsonConfiguration.explicitNulls to a stable API

This configuration flag has been around for a long time and got positive feedback. Therefore, we are promoting it to a stable state. It also received functionality enhancements when used with JsonConfiguration.coerceInputValues (#2586). See related PR for details.

oneof support in ProtoBuf

oneof fields in protobuf messages represent a set of optional fields, where the only one of them is present. With the help of the new @ProtoOneOf annotation, you can naturally map them to Kotlin's sealed class hierarchy. Check out the comprehensive guide for this feature here.

This functionality was contributed to us by xzk.

Other improvements and bugfixes

  • Update okio to 3.9.0 version (#2671)
  • Add extension to access original descriptor from one made with SerialDescriptor.nullable (#2633) (thanks to Chuckame)
  • Use @SerialName of inline polymorphic children in Json (#2601) (thanks to Tad Fisher)
  • Fix serializing nulls for a property of a parameterized type with a nullable upper bound with Protobuf (#2561) (thanks to Shreck Ye)
  • Fixed type discriminator value for custom serializer that uses encodeJsonElement (#2628)
  • Refine exception messages in case of deserializing data from JsonElement. (#2648)
kotlinx.serialization - 1.6.3

Published by sandwwraith 8 months ago

This release provides a couple of new features and uses Kotlin 1.9.22 as default.

Class discriminator output mode

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.

Other features

  • Add kebab-case naming strategy (#2531) (thanks to Emil Kantis)
  • Add value class support to the ProtoBufSchemaGenerator (#2542) (thanks to Felipe Rotilho)

Bugfixes and improvements

  • Fix: Hocon polymorphic serialization in containers (#2151) (thanks to LichtHund)
  • Actualize lenient mode documentation (#2568)
  • Slightly improve error messages thrown from serializer() function (#2533)
  • Do not try to coerce input values for properties (#2530)
  • Make empty objects and arrays collapsed in pretty print mode (#2506)
  • Update Gradle dokka configuration to make sure "source" button is visible in all API docs (#2518, #2524)
kotlinx.serialization - 1.6.2

Published by sandwwraith 11 months ago

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.

  • Add Wasm WASI target (#2510)
  • Bring back linuxArm32Hfp target because it is deprecated, but not removed yet. (#2505)
kotlinx.serialization - 1.6.1

Published by sandwwraith 11 months ago

This release uses Kotlin 1.9.20 by default, while upcoming 1.9.21 is also supported.

Trailing commas in Json

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.

Support of WasmJs target

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.

Bugfixes and improvements

  • Fix TaggedDecoder nullable decoding (#2456) (thanks to Phillip Schichtel)
  • Fix IllegalAccessException for some JPMS boundaries (#2469)
  • Cbor: check if inline value classes are marked as @ByteString (#2466) (thanks to eater)
  • Improve polymorphic deserialization optimization (#2481)
  • Update Okio dependency to 3.6.0 (#2473)
  • Add protobuf conformance tests (#2404) (thanks to Doğaç Eldenk)
  • Support decoding maps with boolean keys (#2440)
kotlinx.serialization - 1.6.0

Published by sandwwraith about 1 year ago

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.

Bugfixes

  • Improve error messages from Json parser (#2406)
  • Mark @SerialName, @Required and @Transient with @MustBeDocumented (#2407)
  • Ensure that no additional files except java compiler output get into multi-release jar (#2405)
  • Fix enums with negative numbers in protobuf not serializing & de-serializing (#2400) (thanks to Doğaç Eldenk)
kotlinx.serialization - 1.6.0-RC

Published by sandwwraith about 1 year ago

This release is based on the Kotlin 1.9.0.

Removal of Legacy JS target

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.

Case insensitivity for enums in Json

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.

Other bugfixes and enhancements

  • Add support to decode numeric literals containing an exponent (#2227) (thanks to Roberto Blázquez)
  • Fix NoSuchMethodError related to Java 8 API compatibility (#2328, #2350) (thanks to Björn Kautler)
  • Changed actual FormatLanguage annotation for JS and Native to avoid problems with duplicating org.intellij.lang.annotations.Language (#2390, #2379)
  • Fix error triggered by 'consume leading class discriminator' polymorphic parsing optimization (#2362)
  • Fix runtime error with Serializer for Nothing on the JS target (#2330) (thanks to Shreck Ye)
  • Fix beginStructure in JsonTreeDecoder when inner structure descriptor is same as outer (#2346) (thanks to Ugljesa Jovanovic)
  • Actualize 'serializer not found' platform-specific message (#2339)
  • Fixed regression with serialization using a list parametrized with contextual types (#2331)
kotlinx.serialization - 1.5.1

Published by sandwwraith over 1 year ago

This release contains an important Native targets overhaul, as well as numerous enhancements and bugfixes.
Kotlin 1.8.21 is used by default.

New set of Native targets

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.

Improvements in Json elements

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.

Other enhancements

  • Potential source-breaking change: Rename json-okio target variables to sink (#2226)
  • Function to retrieve KSerializer by KClass and type arguments serializers (#2291)
  • Added FormatLanguage annotation to Json methods (#2234)
  • Properties Format: Support sealed/polymorphic classes as class properties (#2255)

Bugfixes

  • KeyValueSerializer: Fix missing call to endStructure() (#2272)
  • ObjectSerializer: Respect sequential decoding (#2273)
  • Fix value class encoding in various corner cases (#2242)
  • Fix incorrect json decoding iterator's .hasNext() behavior on array-wrapped inputs (#2268)
  • Fix memory leak caused by invalid KTypeWrapper's equals method (#2274)
  • Fixed NoSuchMethodError when parsing a JSON stream on Java 8 (#2219)
  • Fix MissingFieldException duplication (#2213)
kotlinx.serialization - 1.5.0

Published by sandwwraith over 1 year ago

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.

HoconEncoder and HoconDecoder interfaces and HOCON-specific serializers

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!

Ability to read buffered huge strings in custom Json deserializers

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.

Bugfixes

  • Improve runtime exceptions messages (#2180)
  • Added support for null values for nullable enums in lenient mode (#2176)
  • Prevent class loaders from leaking when using ClassValue cache (#2175)
kotlinx.serialization - 1.5.0-RC

Published by sandwwraith over 1 year ago

This is a release candidate for the next version with many new features to try.
It uses Kotlin 1.8.0 by default.

Json naming strategies

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.

Json unquoted literals

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.

Stabilization of serializer(java.lang.Type) function family

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.

Deprecations in module builders for polymorphism

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.

Bundled Proguard rules

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.

Support for kotlin.Duration in HOCON format

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.

Functional and performance improvements

  • Make DeserializationStrategy covariant at declaration-site (#1897) (thanks to Lukellmann)
  • Added support for the kotlin.Nothing class as built-in (#1991, #2150)
  • Further improve stream decoding performance (#2101)
  • Introduce CharArray pooling for InputStream decoding (#2100)
  • Consolidate exception messages and improve them (#2068)

Bugfixes

  • Add stable hashCode()/equals() calculation to PrimitiveSerialDescriptor (#2136) (thanks to Vasily Vasilkov)
  • Added a factory that creates an enum serializer with annotations on the class (#2125)
  • Correctly handle situation where different serializers can be provided for the same KClass in SealedClassSerializer (#2113)
  • Fixed serializers caching for parametrized types from different class loaders (#2070)
kotlinx.serialization - 1.4.1

Published by sandwwraith almost 2 years ago

This patch release contains several bug fixes and improvements.
Kotlin 1.7.20 is used by default.

Improvements

  • Add @MustBeDocumented to certain annotations (#2059)
  • Deprecate .isNullable in SerialDescriptor builder (#2040)
  • Unsigned primitives and unsigned arrays serializers can be retrieved as built-ins (#1992)
  • Serializers are now cached inside reflective lookup, leading to faster serializer retrieval (#2015)
  • Compiler plugin can create enum serializers using static factories for better speed (#1851) (Kotlin 1.7.20 required)
  • Provide a foundation for compiler plugin intrinsics available in Kotlin 1.8.0 (#2031)

Bugfixes

  • Support polymorphism in Properties format (#2052) (thanks to Rodrigo Vedovato)
  • Added support of UTF-16 surrogate pairs to okio streams (#2033)
  • Fix dependency on core module from HOCON module (#2020) (thanks to Osip Fatkullin)
kotlinx.serialization - 1.4.0

Published by sandwwraith about 2 years ago

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.

Bugfixes

  • Fixed decoding of huge JSON data for okio streams (#2006)
kotlinx.serialization - 1.4.0-RC

Published by sandwwraith about 2 years ago

This is a candidate for the next big release with many new exciting features to try.
It uses Kotlin 1.7.10 by default.

Integration with Okio's BufferedSource and BufferedSink

Okio library by Square is a popular solution for fast and efficient IO operations on JVM, K/N and K/JS.
In this version, we have added functions that parse/write JSON directly to Okio's input/output classes, saving you the overhead of copying data to String beforehand.
These functions are called Json.decodeFromBufferedSource and Json.encodeToBufferedSink, respectively.
There's also decodeBufferedSourceToSequence that behaves similarly to decodeToSequence from Java streams integration, so you can lazily decode multiple objects the same way as before.

Note that these functions are located in a separate new artifact, so users who don't need them wouldn't find themselves dependent on Okio.
To include this artifact in your project, use the same group id org.jetbrains.kotlinx and artifact id kotlinx-serialization-json-okio.
To find out more about this integration, check new functions' documentation and corresponding pull requests:
#1901 and #1982.

Inline classes and unsigned numbers do not require experimental annotations anymore

Inline classes and unsigned number types have been promoted to a Stable feature in Kotlin 1.5,
and now we are promoting support for them in kotlinx.serialization to Stable status, too.
To be precise, we've removed all @ExperimentalSerializationApi annotations from functions related to inline classes encoding and decoding,
namely SerialDescriptor.isInline, Encoder.encodeInline, and some others. We've also updated related documentation article.

Additionally, all @ExperimentalUnsignedTypes annotations were removed completely,
so you can freely use types such as UInt and their respective serializers as a stable feature
without opt-in requirement.

Part of SerializationException's hierarchy is public now

When kotlinx.serialization 1.0 was released, all subclasses of SerializationException were made internal,
since they didn't provide helpful information besides the standard message.
Since then, we've received a lot of feature requests with compelling use-cases for exposing some of these internal types to the public.
In this release, we are starting to fulfilling these requests by making MissingFieldException public.
One can use it in the catch clause to better understand the reasons of failure — for example, to return 400 instead of 500 from an HTTP server — and then use its fields property to communicate the message better.
See the details in the corresponding PR.

In future releases, we'll continue work in this direction, and we aim to provide more useful public exception types & properties.
In the meantime, we've revamped KDoc for some methods regarding the exceptions — all of them now properly declare which exception types are allowed to be thrown.
For example, KSerializer.deserialize is documented to throw IllegalStateException to indicate problems unrelated to serialization, such as data validation in classes' constructors.

@MetaSerializable annotation

This release introduces a new @MetaSerializable annotation that adds @Serializable behavior to user-defined annotations — i.e., those annotations would also instruct the compiler plugin to generate a serializer for class. In addition, all annotations marked with @MetaSerializable are saved in the generated @SerialDescriptor
as if they are annotated with @SerialInfo.

This annotation will be particularly useful for various format authors who require adding some metadata to the serializable class — this can now be done using a single annotation instead of two, and without the risk of forgetting @Serializable. Check out details & examples in the KDoc and corresponding PR.

Note: Kotlin 1.7.0 or higher is required for this feature to work.

Moving documentation from GitHub pages to kotlinlang.org

As a part of a coordinated effort to unify kotlinx libraries users' experience, Dokka-generated documentation pages (KDoc) were moved from https://kotlin.github.io/kotlinx.serialization/ to https://kotlinlang.org/api/kotlinx.serialization/. No action from you is required — there are proper redirects at the former address, so there is no need to worry about links in your blogpost getting obsolete or broken.

Note that this move does not affect guides written in Markdown in the docs folder. We aim to move them later, enriching text with runnable examples as in the Kotlin language guides.

Other improvements

  • Allow Kotlin's null literal in JSON DSL (#1907) (thanks to Lukellmann)
  • Stabilize EmptySerializersModule (#1921)
  • Boost performance of polymorphic deserialization in optimistic scenario (#1919)
  • Added serializer for the kotlin.time.Duration class (plugin support comes in Kotlin 1.7.20) (#1960)
  • Support tagged not null marks in TaggedEncoder/Decoder (#1954) (thanks to EdwarDDay)

Bugfixes

  • Support quoting unsigned integers when used as map keys (#1969)
  • Fix protocol buffer enum schema generation (#1967) (thanks to mogud)
  • Support diamond inheritance of sealed interfaces in SealedClassSerializer (#1958)
  • Support retrieving serializer for sealed interface (#1968)
  • Fix misleading token description in JSON errors (#1941) (thanks to TheMrMilchmann)
kotlinx.serialization - 1.3.3

Published by sandwwraith over 2 years ago

This release contains support for Protocol Buffers packed fields, as well as several bugfixes.
It uses Kotlin 1.6.21 by default.

Protobuf packed fields

It is now possible to encode and decode Kotlin classes to/from Protobuf messages with packed repeated fields.
To mark the field as packed, use @ProtoPacked annotation on it.
Note it affects only List and primitive collection such as IntArray types.
With this feature, it is now possible to decode Proto3 messages, where all repeated fields are packed by default.
Protobuf schema generator also supports new @ProtoPacked annotation.

Many thanks to Paul de Vrieze for his valuable contribution!

Other improvements & small features

  • Incorporate JsonPath into exception messages (#1841)
  • Mark block in corresponding encodeStructure/decodeStructure extensions as crossinline to reduce amount of bytecode (#1917)
  • Support serialization of compile-time Collection<E> properties that are not lists at the runtime (#1821)
  • Best-effort kotlin reflect avoidance in serializer(Type) (#1819)

Bugfixes

  • Iterate over element indices in ObjectSerializer in order to let the format skip unknown keys (#1916)
  • Correctly support registering both default polymorphic serializer & deserializer (#1849)
  • Make error message for captured generic type parameters much more straightforward (#1863)
kotlinx.serialization - 1.3.2

Published by sandwwraith almost 3 years ago

This release contains several features and bugfixes for core API as well as for HOCON format.
It uses Kotlin 1.6.10 by default.

Serializing objects to HOCON

It's now possible to encode Kotlin objects to Config values with new Hocon.encodeToConfig function.
This feature may help edit existing configs inside Kotlin program or generate new ones.

Big thanks to Osip Fatkullin for implementing this.

Polymorphic default serializers

As of now, polymorphicDefault clause inside SerializersModule { } builder specifies a
fallback serializer to be used only during deserialization process. A new function has been introduced to allow setting
fallback serializer for serialization: polymorphicDefaultSerializer.
This function should ease serializing vast hierarchies of third-party or Java classes.

Note that there are two new experimental functions, polymorphicDefaultSerializer and polymorphicDefaultDeserializer.
To avoid naming confusion, we are going to deprecate polymorphicDefault in favor of polymorphicDefaultDeserializer in the next minor release (1.4.0).

Credit for the PR goes to our contributor Joseph Burton.

Other improvements

  • HOCON: parse strings into integers and booleans if possible (#1795) (thanks to tobiaslieber)
  • Add an encodeCollection extensions (#1749) (thanks to Nicklas Ansman Giertz)

Bugfixes

  • Properly handle top-level value classes in encodeToJsonElement (#1777)
  • Fix incorrect handling of object end when JsonTreeReader (JsonElement) is used with decodeToSequence (#1782)
kotlinx.serialization - 1.3.1

Published by sandwwraith almost 3 years ago

This release mainly contains bugfixes for 1.3.0 and provides new experimental Json.decodeToSequence function.

Improvements

  • Provide decodeToSequence to read multiple objects from stream lazily (#1691)

Bugfixes

  • Correctly handle buffer boundaries while decoding escape sequences from json stream (#1706)
  • Properly skip unknown keys for objects and structures with zero properties (#1720)
  • Fix merging for maplikeSerializer when the map is not empty (by using the actual size * 2). (#1712) (thanks to pdvrieze)
  • Fix lookup of primitive array serializers by Java type token (#1708)
kotlinx.serialization - 1.3.0

Published by sandwwraith about 3 years ago

This release contains all of the cool new features from 1.3.0-RC as well as minor improvements.
It uses Kotlin 1.5.31 by default.

Bugfixes and improvements

  • Promote JsonConfiguration and its usages to stable (#1690)
  • Remove opt-in annotations from SerialFormat, StringFormat, BinaryFormat (#1688)
  • Correctly throw SerializationException instead of IOOBE for some cases with EOF in streams (#1677)
  • CBOR: ignore tags when reading (#1614) (thanks to David Robertson)
kotlinx.serialization - 1.3.0-RC

Published by sandwwraith about 3 years ago

This is a release candidate for the next version. It contains a lot of interesting features and improvements,
so we ask you to evaluate it and share your feedback.
Kotlin 1.5.30 is used by default.

Java IO stream-based JSON serialization

Finally, in kotlinx.serialization 1.3.0 we’re presenting the first experimental version of the serialization API for IO streams:
Json.encodeToStream and Json.decodeFromStream extension functions.
With this API, you can decode objects directly from files, network connections, and other data sources without reading the data to strings beforehand.
The opposite operation is also available: you can send encoded objects directly to files and other streams in a single API call.
IO stream serialization is available only on the JVM platform and for the JSON format for now.

Check out more in the PR.

Property-level control over defaults values encoding

Previous versions of the library allowed to specify whether to encode or drop default properties values with
format configuration flags such as Json { encodeDefaults = false }.
In 1.3.0 we’re extending this feature by adding a new way to fine-tune the serialization of default values:
you can now control it on the property level using the new @EncodeDefault annotation.

@EncodeDefault annotation has a higher priority over the encodeDefaults property and takes one of two possible values:

  • ALWAYS (default value) encodes a property value even if it equals to default.
  • NEVER doesn’t encode the default value regardless of the format configuration.

Encoding of the annotated properties is not affected by encodeDefaults format flag
and works as described for all serialization formats, not only JSON.

To learn more, check corresponding PR.

Excluding null values from JSON serialization

In 1.3.0, we’re introducing one more way to reduce the size of the generated JSON strings: omitting null values.
A new JSON configuration property explicitNulls defines whether null property values should be included in the serialized JSON string.
The difference from encodeDefaults is that explicitNulls = false flag drops null values even if the property does not have a default value.
Upon deserializing such a missing property, a null or default value (if it exists) will be used.

To maintain backwards compatibility, this flag is set to true by default.
You can learn more in the documentation or the PR.

Per-hierarchy polymorphic class discriminators

In previous versions, you could change the discriminator name using the
classDiscriminator property of the Json instance.
In 1.3.0, we’re adding a way to set a custom discriminator name for each class hierarchy to enable more flexible serialization.
You can do it by annotating a class with @JsonClassDiscriminator with the discriminator name as its argument.
A custom discriminator is applied to the annotated class and its subclasses.
Only one custom discriminator can be used in each class hierarchy, thanks to the new @InheritableSerialInfo annotation.

Check out corresponding PR for details.

Support for Java module system

Now all kotlinx.serialization runtime libraries are shipped as a multi-release JAR with module-info.class file for Java versions 9 and higher.
This enables possibilities to use kotlinx.serialization with modern tools such as jlink and various technologies such as TorandoFX.

Many thanks to our contributor Gerard de Leeuw and his PR for making this possible.

Native targets for Apple Silicon

This release includes klibs for new targets, introduced in Kotlin/Native 1.5.30 —
macosArm64, iosSimulatorArm64, watchosSimulatorArm64, and tvosSimulatorArm64.

Bugfixes and improvements

  • Properly handle quoted 'null' literals in lenient mode (#1637)
  • Switch on deep recursive function when nested level of JSON is too deep (#1596)
  • Support for local serializable classes in IR compiler
  • Support default values for @SerialInfo annotations in IR compiler
  • Improve error message for JsonTreeReader (#1597)
  • Add guide for delegating serializers and wrapping serial descriptor (#1591)
  • Set target JVM version to 8 for Hocon module in Gradle metadata (#1661)
kotlinx.serialization - 1.2.2

Published by sandwwraith over 3 years ago

This release contains various bugfixes, some useful features and important performance improvements.
It also uses Kotlin 1.5.20 as default.

Features

  • Support for @JsonNames and coerceInputValues in Json.decodeFromDynamic (#1479)
  • Add factory function to wrap a serial descriptor with a custom name for custom delegating serializers (#1547) (thanks to Fadenfire)
  • Allow contextually serialized types to be used as map keys in Json (#1552) (thanks to pdvrieze)

Bugfixes and performance improvements

  • Update size in JsonStringBuilder slow-path to avoid excessive array-copies for large strings with escape symbols (#1491)
  • Optimize integer encoding length in CBOR (#1570) (thanks to davertay)
  • Throw JsonDecodingException instead of ClassCastException during unexpected null in TreeJsonDecoder (#1550)
  • Prohibit 'null' strings in lenient mode in order to get rid of 'null' and "null" ambiguity (#1549)
  • Avoid usage of reflective-like serialDescriptor<KType> in production sources (#1540)
  • Added correct error message when deserializing missing enum member for Properties format (#1539)
  • Make DescriptorSchemaCache in Json thread-local on Native (#1484)