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

@file:UseContextualSerialization doesn't work on Kotlin 2.0.20-RC2 #2783

Closed
vladimirfx opened this issue Aug 15, 2024 · 1 comment
Closed

Comments

@vladimirfx
Copy link

Describe the bug

@file:UseContextualSerialization annotation simply doesn't work starting from Kotlin 2.0.0 up to 2.0.20-RC2. Compilation fails with:

Serializer has not been found for type 'java.util.UUID'. To use context serializer as fallback, explicitly annotate type or property with @Contextual

To Reproduce

@file:UseContextualSerialization(
    forClasses = [
        UUID::class,
    ]
)

package reproducer

import kotlinx.serialization.Serializable
import kotlinx.serialization.UseContextualSerialization
import java.util.UUID

@Serializable
data class ContextualSerializer(val uuid: UUID)

Reproducer project:
use-contextual-serializer-bug.zip

Expected behavior

The code above should compile normally.

Environment

  • Kotlin version: 2.0.0 - 2.0.20-RC2
  • Library version: 1.7.1
  • Kotlin platforms: JVM
  • Gradle version: 8.10
  • Java: 21
@sandwwraith
Copy link
Member

Thanks for the report. Apparently @file:UseContextualSerialization(UUID::class) or @file:UseContextualSerialization(UUID::class, Date::class) work as expected but @file:UseContextualSerialization(forClasses = [UUID::class]) does not. That is... not what I expected from compiler plugin API.

@sandwwraith sandwwraith self-assigned this Aug 15, 2024
sandwwraith added a commit to JetBrains/kotlin that referenced this issue Aug 20, 2024
…le-level annotations

such as @UseContextualSerialization and @UseSerializers.

Fixes Kotlin/kotlinx.serialization#2783
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants