xref: /aosp_15_r20/external/kotlinx.serialization/docs/compatibility.md (revision 57b5a4a64c534cf7f27ac9427ceab07f3d8ed3d8)
1*57b5a4a6SAndroid Build Coastguard Worker# Compatibility policy
2*57b5a4a6SAndroid Build Coastguard Worker
3*57b5a4a6SAndroid Build Coastguard WorkerThis document describes the compatibility policy of kotlinx.serialization library since version 1.0.0 and Kotlin 1.4.0.
4*57b5a4a6SAndroid Build Coastguard Worker
5*57b5a4a6SAndroid Build Coastguard WorkerNote that content of this document is applicable only for **stable** Kotlin platforms (currently Kotlin/JVM and classic Kotlin/JS),
6*57b5a4a6SAndroid Build Coastguard Workersince other experimental platforms currently do not impose any backward-compatibility guarantees.
7*57b5a4a6SAndroid Build Coastguard WorkerYou can check out what platforms are considered to be stable on [this page](https://kotlinlang.org/docs/reference/evolution/components-stability.html).
8*57b5a4a6SAndroid Build Coastguard Worker
9*57b5a4a6SAndroid Build Coastguard Worker- [Core library compatibility](#core-library-compatibility)
10*57b5a4a6SAndroid Build Coastguard Worker  * [General (Stable) API](#stable-api)
11*57b5a4a6SAndroid Build Coastguard Worker  * [Experimental API](#experimental-api)
12*57b5a4a6SAndroid Build Coastguard Worker  * [Internal API](#internal-api)
13*57b5a4a6SAndroid Build Coastguard Worker- [Compatibility with Kotlin compiler plugin](#compatibility-with-kotlin-compiler-plugin)
14*57b5a4a6SAndroid Build Coastguard Worker
15*57b5a4a6SAndroid Build Coastguard Worker## Core library compatibility
16*57b5a4a6SAndroid Build Coastguard Worker
17*57b5a4a6SAndroid Build Coastguard WorkerCore library public API comes in three flavours: general (stable), experimental, and internal.
18*57b5a4a6SAndroid Build Coastguard WorkerAll public API except stable is marked with the corresponding annotation.
19*57b5a4a6SAndroid Build Coastguard WorkerTo learn how to use declarations that require opt-in, please refer to [corresponding documentation page](https://kotlinlang.org/docs/reference/opt-in-requirements.html#non-propagating-use).
20*57b5a4a6SAndroid Build Coastguard Worker
21*57b5a4a6SAndroid Build Coastguard Worker### Stable API
22*57b5a4a6SAndroid Build Coastguard Worker
23*57b5a4a6SAndroid Build Coastguard WorkerStable API is guaranteed to preserve its ABI and documented semantics:
24*57b5a4a6SAndroid Build Coastguard Worker
25*57b5a4a6SAndroid Build Coastguard Worker* It cannot change its semantics expressed in its documentation.
26*57b5a4a6SAndroid Build Coastguard Worker* It is binary backwards-compatible: during update of `kotlinx.serialization` version, previously compiled code will continue to work.
27*57b5a4a6SAndroid Build Coastguard Worker    For example, for a library that depends only on `kotlinx.serialization` stable API,
28*57b5a4a6SAndroid Build Coastguard Worker    clients of the library can easily depend on a next `kotlinx.serialization` version and expect everything to work.
29*57b5a4a6SAndroid Build Coastguard Worker* It is source backwards compatible modulo major deprecation. Most of the API is here to stay forever,
30*57b5a4a6SAndroid Build Coastguard Workerunless an unfixable security or design flaw is exposed. Minor releases never add source-incompatible changes to the stable API.
31*57b5a4a6SAndroid Build Coastguard Worker
32*57b5a4a6SAndroid Build Coastguard Worker#### Deprecation cycle
33*57b5a4a6SAndroid Build Coastguard Worker
34*57b5a4a6SAndroid Build Coastguard WorkerWhen API is deprecated, it goes through multiple stages and there is at least one major release between each stages.
35*57b5a4a6SAndroid Build Coastguard Worker
36*57b5a4a6SAndroid Build Coastguard Worker1. Feature is deprecated with compilation warning. Most of the time, proper replacement (and corresponding `replaceWith` declaration) is provided to automatically migrate deprecated usages with a help of IntelliJ IDEA.
37*57b5a4a6SAndroid Build Coastguard Worker2. Deprecation level is increased to error or hidden. It is no longer possible to compile new code against deprecated API, though it is still present in the ABI.
38*57b5a4a6SAndroid Build Coastguard Worker3. API is completely removed. While we give our best efforts not to do so and have no plans of removing any API, we still are leaving this option in case of unforeseen problems such as security issues.
39*57b5a4a6SAndroid Build Coastguard Worker
40*57b5a4a6SAndroid Build Coastguard Worker
41*57b5a4a6SAndroid Build Coastguard Worker### Experimental API
42*57b5a4a6SAndroid Build Coastguard Worker
43*57b5a4a6SAndroid Build Coastguard WorkerThis API marked as `@ExperimentalSerializationApi`. API is marked experimental when its design has potential open questions which may eventually lead to either semantics changes of the API or its deprecation.
44*57b5a4a6SAndroid Build Coastguard WorkerBy default, most of the new API is marked as experimental and becomes stable in one of the next releases if no new issues arise. Otherwise, either semantics is fixed without changes in ABI or API goes through deprecation cycle.
45*57b5a4a6SAndroid Build Coastguard Worker
46*57b5a4a6SAndroid Build Coastguard WorkerHowever, we'll try to provide best-effort compatibility — such declarations won't be deleted or changed instantly,
47*57b5a4a6SAndroid Build Coastguard Workerthey will go through deprecation cycle if this is possible. However, this deprecation cycle may be faster than usual.
48*57b5a4a6SAndroid Build Coastguard Worker
49*57b5a4a6SAndroid Build Coastguard WorkerUsage notes:
50*57b5a4a6SAndroid Build Coastguard Worker
51*57b5a4a6SAndroid Build Coastguard Worker* Experimental API can be used in your applications if maintenance cost is clear:
52*57b5a4a6SAndroid Build Coastguard Workeradditional migrations may have to be performed during `kotlinx.serialization` update.
53*57b5a4a6SAndroid Build Coastguard Worker
54*57b5a4a6SAndroid Build Coastguard Worker* Experimental API can be used in other **experimental** API (for example, a custom serialization format).
55*57b5a4a6SAndroid Build Coastguard WorkerIn such cases, clients of the API have to be aware about experimentality.
56*57b5a4a6SAndroid Build Coastguard Worker
57*57b5a4a6SAndroid Build Coastguard Worker* It's not recommended to use it as a dependency in your **stable** API, even as an implementation detail.
58*57b5a4a6SAndroid Build Coastguard WorkerDue to the lack of binary backward compatibility, your clients may experience behavioural changes
59*57b5a4a6SAndroid Build Coastguard Workeror runtime exceptions when an unexpected version of `kotlinx.serialization` gets included in the runtime classpath.
60*57b5a4a6SAndroid Build Coastguard Worker
61*57b5a4a6SAndroid Build Coastguard Worker### Internal API
62*57b5a4a6SAndroid Build Coastguard Worker
63*57b5a4a6SAndroid Build Coastguard WorkerThis API is marked with `@InternalSerializationApi` or located in `kotlinx.serialization.internal` package.
64*57b5a4a6SAndroid Build Coastguard WorkerIt does not have any binary or source compatibility guarantees and can be deprecated or deleted without replacement at any time.
65*57b5a4a6SAndroid Build Coastguard Worker
66*57b5a4a6SAndroid Build Coastguard WorkerIt is not recommended to use it.
67*57b5a4a6SAndroid Build Coastguard WorkerHowever, if you have a rare use-case that can be solved only with internal API, it is possible to use it.
68*57b5a4a6SAndroid Build Coastguard WorkerIn such a case, please create an issue on GitHub in order for us to understand a use-case and to provide stable alternative.
69*57b5a4a6SAndroid Build Coastguard Worker
70*57b5a4a6SAndroid Build Coastguard Worker## Compatibility with Kotlin compiler plugin
71*57b5a4a6SAndroid Build Coastguard Worker
72*57b5a4a6SAndroid Build Coastguard Worker`kotlinx.serialization` also has the compiler plugin, that generates code depending on the core library.
73*57b5a4a6SAndroid Build Coastguard WorkerTherefore, the compiler plugin should be compatible with the runtime library to work.
74*57b5a4a6SAndroid Build Coastguard WorkerKotlin & `kotlinx.serialization` plugin 1.4.0/1.4.10 are compatible with 1.0.0 runtime library.
75*57b5a4a6SAndroid Build Coastguard Worker
76*57b5a4a6SAndroid Build Coastguard WorkerFor further updates, we have the following policy:
77*57b5a4a6SAndroid Build Coastguard Worker
78*57b5a4a6SAndroid Build Coastguard Worker* New Kotlin compiler plugins should be backward compatible with core library.
79*57b5a4a6SAndroid Build Coastguard WorkerIt means that it is possible to freely update Kotlin version in a project without changing the code
80*57b5a4a6SAndroid Build Coastguard Workerand without the need to update `kotlinx.serialization` runtime.
81*57b5a4a6SAndroid Build Coastguard WorkerIn other words, `1.0.0` runtime can be used with any of Kotlin `1.4.x` versions.
82*57b5a4a6SAndroid Build Coastguard Worker
83*57b5a4a6SAndroid Build Coastguard Worker* New Kotlin compiler plugin features may require new `kotlinx.serialization` library.
84*57b5a4a6SAndroid Build Coastguard WorkerFor example, if Kotlin `1.4.x` gets serialization of unsigned integers,
85*57b5a4a6SAndroid Build Coastguard Workerit would require a corresponding runtime version higher than `1.0.0`.
86*57b5a4a6SAndroid Build Coastguard WorkerThis would be indicated by a compiler error specific to a particular feature.
87*57b5a4a6SAndroid Build Coastguard Worker
88*57b5a4a6SAndroid Build Coastguard Worker* New core library versions may or may not require Kotlin compiler plugin update,
89*57b5a4a6SAndroid Build Coastguard Workerdepending on a particular release.
90*57b5a4a6SAndroid Build Coastguard WorkerWe'll try to avoid these situations; however, in case of some unexpected issues, it may be necessary.
91*57b5a4a6SAndroid Build Coastguard WorkerSo it is possible to have a situation where upgrading serialization runtime from `1.x` to `1.y` requires an update of Kotlin version from `1.4.0` to `1.4.x`.
92*57b5a4a6SAndroid Build Coastguard WorkerThe compiler can detect such problems and will inform you if its version is incompatible with a current version of core library.
93