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