Skip to content
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
merged 2 commits into from
Mar 19, 2024

Conversation

sandwwraith
Copy link
Member

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

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
Copy link
Member Author

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
@sandwwraith sandwwraith merged commit b811fa3 into dev Mar 19, 2024
4 checks passed
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.
@shanshin shanshin deleted the interface-contextual branch August 2, 2024 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants