Kotlin/kotlinx.serialization
Compare Source
==================
This is patch release contains several bugfixes 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 foundation for compiler plugin intrinsics available in Kotlin 1.8.0 (#2031)
Bugfixes
==================
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)
==================
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)
==================
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
Bugfixes
- Properly handle top-level value classes in encodeToJsonElement (#1777)
- Fix incorrect handling of object end when JsonTreeReader (JsonElement) is used with decodeToSequence (#1782)
==================
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)
==================
This release contains all of the cool new features from 1.3.0-RC (see below) 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)
==================
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)
==================
This release mainly contains bugfixes for various issues, including important broken thread-safety and improper encoding.
Features
- Added support for nullable values, nested and empty collections in protobuf (#1430)
Bugfixes
- Support @JsonNames for enum values (#1473)
- Handle EOF in skipElement correctly (#1475)
- Allow using value classes with primitive carriers as map keys (#1470)
- Read JsonNull only for non-string literals in JsonTreeReader (#1466)
- Properly reuse JsonStringBuilders in CharArrayPool (#1455)
- Properly ensure capacity of the string builder on the append slow-path (#1441)
==================
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 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).
==================
This release contains all features and bugfixes from 1.1.0-RC plus an additional fix for incorrect exception type
(#1325 — Throw SerializationException
instead of IllegalStateException
in EnumSerializer
) and uses release version of Kotlin 1.4.30.
In the light of JCenter shutdown, starting from 1.1.0-RC and now on,
all new releases of kotlinx.serialization are published directly to Maven Central and therefore are not available in https://kotlin.bintray.com/kotlinx/
repository.
We suggest you to remove jcenter()
and other kotlin bintray repositories from your buildscripts and to use mavenCentral()
repository instead.