[KT-84952]Generate explicit typeParametersSerializers() for all GeneratedSerializer implementations#5744
Open
lamaxama wants to merge 1 commit intoJetBrains:masterfrom
Open
[KT-84952]Generate explicit typeParametersSerializers() for all GeneratedSerializer implementations#5744lamaxama wants to merge 1 commit intoJetBrains:masterfrom
lamaxama wants to merge 1 commit intoJetBrains:masterfrom
Conversation
…izer implementations
Code Owners
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #KT-84952
Problem
Starting with kotlinx.serialization 1.8.0, the library switched to "all-compatibility" mode which generates Java 8 default method implementations in interfaces. This causes Android-specific runtime failures when the serialization runtime is used as a
compileOnlydependency.For serializable classes without type parameters, the generated
$serializerclass now calls:The
GeneratedSerializer$-CCclass is generated by d8 desugaring during Android APK compilation from the interface's default methods. However, when kotlinx.serialization is declared ascompileOnly:$-CCcompanion class cannot be generated by d8 because the interface definitions are not available in the compilation classpathNoClassDefFoundError: GeneratedSerializer$-CCThis affects Android plugin/extension architectures where:
compileOnlydependency on serialization$-CCclassReal-world Impact
See keiyoushi/extensions-source#12962 for a detailed analysis and real-world case where this issue blocked upgrading to Kotlin 2.x.
Solution
Modify the Kotlin serialization compiler plugin (K2/FIR) to always generate an explicit
typeParametersSerializers()method implementation for all$serializerclasses that implementGeneratedSerializer, regardless of whether the class has type parameters.Before this change
For classes without type parameters, no
typeParametersSerializers()method was generated. The class relied on the interface default implementation:After this change
All
$serializerclasses explicitly implement the method: