Skip to content

Releases: Kotlin/kotlinx.serialization

1.1.0

19 Feb 23:14
43d5f78
Compare
Choose a tag to compare

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.

1.1.0-RC

04 Feb 11:16
4236a7e
Compare
Choose a tag to compare

This is a release candidate of 1.1.0 version. Note that final 1.1.0 version may include more features and bugfixes,
which would be listed in the corresponding changelog.

Kotlin version requirement updated

Due to changes in calling conventions between compiler plugin and serialization core runtime, this release requires
Kotlin version at least 1.4.30-M1 (we recommend using 1.4.30 release version). However, these changes should not affect your code, because only deprecated functions were removed from public API.
See corresponding PR for the details.

Experimental support for inline classes (IR only)

Using 1.1.0-RC, you can mark inline classes as @Serializable and use them in other serializable classes.
Unsigned integer types (UByte, UShort, UInt and ULong) are serializable as well and have special support in JSON.
This feature requires Kotlin compiler 1.4.30-RC and enabling new IR compilers for JS and JVM.

You can learn more in the documentation and corresponding pull request.

Other features

  • Add serializerOrNull function for KType and Type arguments (#1164)
  • Allow shared prefix names in Properties (#1183) (thanks to TorRanfelt)
  • Add support for encoding/decoding Properties values as Strings (#1158) (thanks to daniel-jasinski)

Bugfixes and performance improvements

  • Support contextual serialization for derived classes (#1277) (thanks to Martin Raison)
  • Ensure serialization is usable from K/N background thread (#1282)
  • Fail on primitive type overflow during JsonElement deserialization (#1300)
  • Throw SerializationException instead of ISE when encountering an invalid boolean in JSON (#1299)
  • Optimize the loop for writing large varints in ProtoBuf (#1294)
  • Fix serializing property with custom accessors and backing field (#1197)
  • Optimize check for missing fields in deserialization and improve MissingFieldException message (#1153)
  • Improved support of nullable serializer in @UseSerializers annotation (#1195)
  • Correctly escape keys in JsonObject.toString() (#1246) (thanks to Karlatemp)
  • Treat Collection as ArrayList in serializer by type lookups (#1257)
  • Do not try to end structure in encode/decode structure extensions if an exception has been thrown, so the original exception will be propagated (#1201)
  • Properly cache serial names in order to improve performance of JSON parser with strict mode (#1209)
  • Fix dynamic serialization for nullable values (#1199) (thanks to ankushg)

1.0.1

28 Oct 14:52
Compare
Choose a tag to compare

This patch release contains several feature improvements as well as bugfixes and performance improvements.

Features

  • Add object-based serialization and deserialization of polymorphic types for dynamic conversions on JS platform (#1122)
  • Add support for object polymorphism in HOCON decoder (#1136)
  • Add support of decoding map in the root of HOCON config (#1106)

Bugfixes

  • Properly cache generated serializers in PluginGeneratedSerialDescriptor (#1159)
  • Add Pair and Triple to serializer resolving from Java type token (#1160)
  • Fix deserialization of half-precision, float and double types in CBOR (#1112)
  • Fix ByteString annotation detection when ByteArray is nullable (#1139) (thanks to Travis Wyatt)

1.0.0

08 Oct 15:24
d51ccbb
Compare
Choose a tag to compare

The first public stable release, yay!
The definitions of stability and backwards compatibility guarantees are located in the corresponding document.
We now also have a GitHub Pages site with full API reference.

Compared to RC2, no new features apart from #947 were added and all previously deprecated declarations and migrations were deleted.
If you are using RC/RC2 along with deprecated declarations, please, migrate before updating to 1.0.0.
In case you are using pre-1.0 versions (e.g. 0.20.0), please refer to our migration guide.

Bugfixes and improvements

  • Support nullable types at top-level for JsonElement decoding (#1117)
  • Add CBOR ignoreUnknownKeys option (#947) (thanks to Travis Wyatt)
  • Fix incorrect documentation of encodeDefaults (#1108) (thanks to Anders Carling)

1.0.0-RC2

21 Sep 15:29
Compare
Choose a tag to compare

Second release candidate for 1.0.0 version. This RC contains tweaks and changes based on users feedback after 1.0.0-RC.

Major changes

JSON format is now located in different artifact (#994)

In 1.0.0-RC, the kotlinx-serialization-core artifact contained core serialization entities as well as Json serial format.
We've decided to change that and to make core format-agnostic.
It would make the life easier for those who use other serial formats and also make possible to write your own implementation of JSON
or another format without unnecessary dependency on the default one.

In 1.0.0-RC2, Json class and related entities are located in kotlinx-serialization-json artifact.
To migrate, simply replace kotlinx-serialization-core dependency with -json. Core library then will be included automatically
as the transitive dependency.

For most use-cases, you should use new kotlinx-serialization-json artifact. Use kotlinx-serialization-core if you are
writing a library that depends on kotlinx.serialization in a format-agnostic way of provides its own serial format.

encodeDefaults flag is now set to false in the default configuration for JSON, CBOR and Protocol Buffers.

The change is motivated by the fact that in most real-life scenarios, this flag is set to false anyway,
because such configuration reduces visual clutter and saves amount of data being serialized.
Other libraries, like GSON and Moshi, also have this behavior by default.

This may change how your serialized data looks like, if you have not set value for encodeDefaults flag explicitly.
We anticipate that most users already had done this, so no migration is required.
In case you need to return to the old behavior, simply add encodeDefaults = true to your configuration while creating Json/Cbor/ProtoBuf object.

Move Json.encodeToDynamic/Json.decodeFromDynamic functions to json package

Since these functions are no longer exposed via DynamicObjectParser/Serializer and they are now Json class extensions,
they should be moved to kotlinx.serialization.json package.
To migrate, simply add import kotlinx.serialization.json.* to your files.

Bugfixes and improvements

  • Do not provide default implementation for serializersModule in AbstractEncoder/Decoder (#1089)
  • Support JsonElement hierarchy in dynamic encoding/decoding (#1080)
  • Support top-level primitives and primitive map keys in dynamic encoding/decoding
  • Change core annotations retention (#1083)
  • Fix 'Duplicate class ... found in modules' on Gradle != 6.1.1 (#996)
  • Various documentation clarifications
  • Support deserialization of top-level nullable types (#1038)
  • Make most serialization exceptions eligible for coroutines exception recovery (#1054)
  • Get rid of methods that do not present in Android API<24 (#1013, #1040)
  • Throw JsonDecodingException on empty string literal at the end of the input (#1011)
  • Remove new lines in deprecation warnings that caused errors in ObjC interop (#990)

1.0.0-RC

17 Aug 10:11
f0a6546
Compare
Choose a tag to compare

Release candidate for 1.0.0 version. The goal of RC release is to collect feedback from users
and provide 1.0.0 release with bug fixes and improvements based on that feedback.

While working on 1.0.0 version, we carefully examined every public API declaration of the library and
split it to stable API, that we promise to be source and binary-compatible,
and experimental API, that may be changed in the future.
Experimental API is annotated with @ExperimentalSerializationApi annotation, which requires opt-in.
For a more detailed description of the guarantees, please refer to the compatibility guide.

The id of the core artifact with @Serializable annotation and Json format was changed
from kotlinx-serialization-runtime to kotlinx-serialization-core to be more clear and aligned with other kotlinx libraries.

A significant part of the public API was renamed or extracted to a separate package.
To migrate from the previous versions of the library, please refer to the migration guide.

API changes

Json

  • Core API changes

    • stringify and parse are renamed to encodeToString and decodeFromString
    • parseJson and fromJson are renamed to parseToJsonElement and decodeFromJsonElement
    • Reified versions of methods are extracted to extensions
  • Json constructor is replaced with Json {} builder function, JsonConfiguration is deprecated in favor
    of Json {} builder

    • All default Json implementations are removed
    • Json companion object extends Json
  • Json configuration

    • prettyPrintIndent allows only whitespaces
    • serializeSpecialFloatingPointValues is renamed to allowSpecialFloatingPointValues. It now affects both serialization and deserialization behaviour
    • unquoted JSON flag is deprecated for removal
    • New coerceInputValues option for null-defaults and unknown enums (#90, #246)
  • Simplification of JsonElement API

    • Redundant members of JsonElement API are deprecated or extracted to extensions
    • Potential error-prone API is removed
    • JsonLiteral is deprecated in favor of JsonPrimitive constructors with nullable parameter
  • JsonElement builders rework to be aligned with stdlib collection builders (#418, #627)

    • Deprecated infix to and unaryPlus in JSON DSL in favor of put/add functions
    • jsonObject {} and json {} builders are renamed to buildJsonObject {} and buildJsonArray {}
    • Make all builders inline (#703)
  • JavaScript support

    • DynamicObjectParser is deprecated in the favor of Json.decodeFromDynamic extension functions
    • Json.encodeToDynamic extension is added as a counterpart to Json.decodeFromDynamic (former DynamicObjectParser) (#116)
  • Other API changes:

    • JsonInput and JsonOutput are renamed to JsonDecoder and JsonEncoder
    • Methods in JsonTransformingSerializer are renamed to transformSerialize and transformDeserialize
    • JsonParametricSerializer is renamed to JsonContentPolymorphicSerializer
    • JsonEncodingException and JsonDecodingException are made internal
  • Bug fixes

    • IllegalStateException when null occurs in JSON input in the place of an expected non-null object (#816)
    • java.util.NoSuchElementException when deserializing twice from the same JsonElement (#807)

Core API for format authoring

  • The new naming scheme for SerialFormats

    • Core functions in StringFormat and BinaryFormat are renamed and now follow the same naming scheme
    • stringify/parse are renamed to encodeToString/decodeFromString
    • encodeToByteArray/encodeToHexString/decodeFromByteArray/decodeFromHexString in BinaryFormat are introduced instead of dump/dumps/load/loads
  • New format instances building convention

    • Constructors replaced with builder-function with the same name to have the ability to add new configuration parameters,
      while preserving both source and binary compatibility
    • Format's companion objects now extend format class and can be used interchangeably
  • SerialDescriptor-related API

    • SerialDescriptor and SerialKind are moved to a separate kotlinx.serialization.descriptors package
    • ENUM and CONTEXTUAL kinds now extend SerialKind directly
    • PrimitiveDescriptor is renamed to PrimitiveSerialDescriptor
    • Provide specific buildClassSerialDescriptor to use with classes' custom serializers, creating other kinds is considered experimental for now
    • Replace extensions that returned lists (e.g. elementDescriptors) with properties that return iterable as an optimization
    • IndexOutOfBoundsException in descriptor.getElementDescriptor(index) for List after upgrade to 0.20.0 is fixed (#739)
  • SerializersModule-related API

    • SerialModule is renamed to SerializersModule
    • SerialModuleCollector is renamed to SerializersModuleCollector
    • All builders renamed to be aligned with a single naming scheme (e.g. SerializersModule {} DSL)
    • Deprecate infix with in polymorphic builder in favor of subclass()
    • Helper-like API is extracted to extension functions where possible.
    • polymorphicDefault API for cases when type discriminator is not registered or absent (#902)
  • Contextual serialization

    • @ContextualSerialization is split into two annotations: @Contextual to use on properties and @UseContextualSerialization to use on file
    • New SerialDescriptor.capturedKClass API to introspect SerializersModule-based contextual and polymorphic kinds (#515, #595)
  • Encoding-related API

    • Encoding-related classes (Encoder, Decoder, AbstractEncoder, AbstractDecoder) are moved to a separate kotlinx.serialization.encoding package
    • Deprecated typeParameters argument in beginStructure/beginCollection methods
    • Deprecated updateSerializableValue and similar methods and UpdateMode enum
    • Renamed READ_DONE to DECODE_DONE
    • Make extensions inline where applicable
    • kotlinx.io mockery (InputStream, ByteArrayInput, etc) is removed
  • Serializer-related API

    • UnitSerializer is replaced with Unit.serializer()
    • All methods for serializers retrieval are renamed to serializer
    • Context is used as a fallback in serializer by KType/Java's Reflect Type functions (#902, #903)
    • Deprecated all exceptions except SerializationException.
    • @ImplicitReflectionSerializer is deprecated
    • Support of custom serializers for nullable types is added (#824)

ProtoBuf

  • ProtoBuf constructor is replaced with ProtoBuf {} builder function
  • ProtoBuf companion object now extends ProtoBuf
  • ProtoId is renamed to ProtoNumber, ProtoNumberType to ProtoIntegerType to be consistent with ProtoBuf specification
  • ProtoBuf performance is significantly (from 2 to 10 times) improved (#216)
  • Top-level primitives, classes and objects are supported in ProtoBuf as length-prefixed tagless messages (#93)
  • SerializationException is thrown instead of IllegalStateException on incorrect input (#870)
  • ProtobufDecodingException is made internal

Other formats

  • All format constructors are migrated to builder scheme
  • Properties serialize and deserialize enums as strings (#818)
  • CBOR major type 2 (byte string) support (#842)
  • ConfigParser is renamed to Hocon, kotlinx-serialization-runtime-configparser artifact is renamed to kotlinx-serialization-hocon
  • Do not write/read size of collection into Properties' map (#743)