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.
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.
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.
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.
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 @EncodeDefaults annotation.
@EncodeDefaults 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 encodeDefault format flag
and works as described for all serialization formats, not only JSON.
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.
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Bumps kotlinx-serialization-json from 1.2.2 to 1.3.0.
Release notes
Sourced from kotlinx-serialization-json's releases.
... (truncated)
Changelog
Sourced from kotlinx-serialization-json's changelog.
... (truncated)
Commits
5ce8e2c
Update changelog4276aa1
Correctly throw SerializationException instead of IOOBE for some cases with E...7285ed3
Prepare 1.3.0 release5a16c22
Add forgottent '@ExperimentalSerializationApi
' on JsonBuilder.explicitNulls (...07c7486
Promote JsonConfiguration and its usages to stable (#1690)0d1dc0e
Remove opt-in annotations from SerialFormat, StringFormat, BinaryFormat (#1688)e1ff8f2
CBOR: ignore tags when reading (#1614)55c9daf
Proofread json.md (#1667)8384772
Use a separate source set for compiling the module descriptor to prevent IDE ...920f589
Prepare 1.3.0-RC release (#1658)Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)