-
Notifications
You must be signed in to change notification settings - Fork 620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change priority for PolymorphicSerializer inside serializer() function #2565
Merged
Conversation
This file contains 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
shanshin
reviewed
Feb 21, 2024
core/commonTest/src/kotlinx/serialization/SerializersLookupNamedCompanionTest.kt
Outdated
Show resolved
Hide resolved
core/commonTest/src/kotlinx/serialization/InterfaceContextualSerializerTest.kt
Show resolved
Hide resolved
shanshin
approved these changes
Mar 15, 2024
Now, we look up serializers for non-sealed interfaces in SerializersModule first, and only then unconditionally return PolymorphicSerializer. This is done because with old behavior, it was impossible to override interface serializer with context, as interfaces were treated as always having PolymorphicSerializer. This is a behavioral change, although impact should be minimal, as for most usecases (without modules), serializer will be the same and special workarounds are performed so cache would also work as expected. Note that KClass.serializer() function will no longer return PolymorphicSerializer for interfaces at all and return null instead. It is OK, because this function is marked with @InternalSerializationApi, and we can change its behavior. Intrinsics in plugin with changed functionality are expected to be merged in 2.0.0-RC. Fixes #2060
sandwwraith
force-pushed
the
interface-contextual
branch
from
March 15, 2024 17:17
c7a647a
to
456ec8c
Compare
Rebased on dev |
sandwwraith
added a commit
to JetBrains/kotlin
that referenced
this pull request
Mar 18, 2024
…rovided for interface. This prioritizes module contents over default polymorphic serializer. See Kotlin/kotlinx.serialization#2060 and Kotlin/kotlinx.serialization#2565
KotlinBuild
pushed a commit
to JetBrains/kotlin
that referenced
this pull request
Mar 18, 2024
…rovided for interface. This prioritizes module contents over default polymorphic serializer. See Kotlin/kotlinx.serialization#2060 and Kotlin/kotlinx.serialization#2565
KotlinBuild
pushed a commit
to JetBrains/kotlin
that referenced
this pull request
Mar 21, 2024
…rovided for interface. This prioritizes module contents over default polymorphic serializer. See Kotlin/kotlinx.serialization#2060 and Kotlin/kotlinx.serialization#2565
sandwwraith
added a commit
that referenced
this pull request
May 16, 2024
because changes related to serializer<T>() when T is non-sealed interface should be synchronized in runtime and plugin intrinsic implementation. See #2565 and JetBrains/kotlin@7c8c65d for details.
sandwwraith
added a commit
that referenced
this pull request
May 16, 2024
because changes related to serializer<T>() when T is non-sealed interface should be synchronized in runtime and plugin intrinsic implementation. See #2565 and JetBrains/kotlin@7c8c65d for details.
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.
Now, we look up serializers for non-sealed interfaces in SerializersModule first, and only then unconditionally return PolymorphicSerializer. This is done because with old behavior, it was impossible to override interface serializer with context, as interfaces were treated as always having PolymorphicSerializer.
This is a behavioral change, although impact should be minimal, as for most usecases (without modules), serializer will be the same and special workarounds are performed so cache would also work as expected.
Note that KClass.serializer() function will no longer return PolymorphicSerializer for interfaces at all and return null instead. It is OK, because this function is marked with @InternalSerializationApi, and we can change its behavior.
Intrinsics in plugin with changed functionality are expected to be merged in 2.0.0-RC.
Fixes #2060