Releases: Kotlin/kotlinx.serialization
1.0.1
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
dynamicconversions 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
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
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
dynamicencoding/decoding (#1080) - Support top-level primitives and primitive map keys in
dynamicencoding/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
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
stringifyandparseare renamed toencodeToStringanddecodeFromStringparseJsonandfromJsonare renamed toparseToJsonElementanddecodeFromJsonElement- Reified versions of methods are extracted to extensions
-
Jsonconstructor is replaced withJson {}builder function,JsonConfigurationis deprecated in favor
ofJson {}builder- All default
Jsonimplementations are removed Jsoncompanion object extendsJson
- All default
-
Json configuration
prettyPrintIndentallows only whitespacesserializeSpecialFloatingPointValuesis renamed toallowSpecialFloatingPointValues. It now affects both serialization and deserialization behaviourunquotedJSON flag is deprecated for removal- New
coerceInputValuesoption for null-defaults and unknown enums (#90, #246)
-
Simplification of
JsonElementAPI- Redundant members of
JsonElementAPI are deprecated or extracted to extensions - Potential error-prone API is removed
JsonLiteralis deprecated in favor ofJsonPrimitiveconstructors with nullable parameter
- Redundant members of
-
JsonElementbuilders rework to be aligned with stdlib collection builders (#418, #627)- Deprecated infix
toand unaryPlus in JSON DSL in favor ofput/addfunctions jsonObject {}andjson {}builders are renamed tobuildJsonObject {}andbuildJsonArray {}- Make all builders
inline(#703)
- Deprecated infix
-
JavaScript support
DynamicObjectParseris deprecated in the favor ofJson.decodeFromDynamicextension functionsJson.encodeToDynamicextension is added as a counterpart toJson.decodeFromDynamic(formerDynamicObjectParser) (#116)
-
Other API changes:
JsonInputandJsonOutputare renamed toJsonDecoderandJsonEncoder- Methods in
JsonTransformingSerializerare renamed totransformSerializeandtransformDeserialize JsonParametricSerializeris renamed toJsonContentPolymorphicSerializerJsonEncodingExceptionandJsonDecodingExceptionare made internal
-
Bug fixes
Core API for format authoring
-
The new naming scheme for
SerialFormats- Core functions in
StringFormatandBinaryFormatare renamed and now follow the same naming scheme stringify/parseare renamed toencodeToString/decodeFromStringencodeToByteArray/encodeToHexString/decodeFromByteArray/decodeFromHexStringinBinaryFormatare introduced instead ofdump/dumps/load/loads
- Core functions in
-
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
- Constructors replaced with builder-function with the same name to have the ability to add new configuration parameters,
-
SerialDescriptor-related API
SerialDescriptorandSerialKindare moved to a separatekotlinx.serialization.descriptorspackageENUMandCONTEXTUALkinds now extendSerialKinddirectlyPrimitiveDescriptoris renamed toPrimitiveSerialDescriptor- Provide specific
buildClassSerialDescriptorto 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 IndexOutOfBoundsExceptionindescriptor.getElementDescriptor(index)forListafter upgrade to 0.20.0 is fixed (#739)
-
SerializersModule-related API
SerialModuleis renamed toSerializersModuleSerialModuleCollectoris renamed toSerializersModuleCollector- All builders renamed to be aligned with a single naming scheme (e.g.
SerializersModule {}DSL) - Deprecate infix
within polymorphic builder in favor of subclass() - Helper-like API is extracted to extension functions where possible.
polymorphicDefaultAPI for cases when type discriminator is not registered or absent (#902)
-
Contextual serialization
-
Encoding-related API
- Encoding-related classes (
Encoder,Decoder,AbstractEncoder,AbstractDecoder) are moved to a separatekotlinx.serialization.encodingpackage - Deprecated
typeParametersargument inbeginStructure/beginCollection methods - Deprecated
updateSerializableValueand similar methods andUpdateModeenum - Renamed
READ_DONEtoDECODE_DONE - Make extensions
inlinewhere applicable kotlinx.iomockery (InputStream,ByteArrayInput, etc) is removed
- Encoding-related classes (
-
Serializer-related API
UnitSerializeris replaced withUnit.serializer()- All methods for serializers retrieval are renamed to
serializer - Context is used as a fallback in
serializerby KType/Java's Reflect Type functions (#902, #903) - Deprecated all exceptions except
SerializationException. @ImplicitReflectionSerializeris deprecated- Support of custom serializers for nullable types is added (#824)
ProtoBuf
ProtoBufconstructor is replaced withProtoBuf {}builder functionProtoBufcompanion object now extendsProtoBufProtoIdis renamed toProtoNumber,ProtoNumberTypetoProtoIntegerTypeto 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)
SerializationExceptionis thrown instead ofIllegalStateExceptionon incorrect input (#870)ProtobufDecodingExceptionis 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)
ConfigParseris renamed toHocon,kotlinx-serialization-runtime-configparserartifact is renamed tokotlinx-serialization-hocon- Do not write/read size of collection into Properties' map (#743)