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

Annotating property type with @Serializable does not override default serializer in typealias #2358

Closed
iseki0 opened this issue Jul 5, 2023 · 1 comment

Comments

@iseki0
Copy link
Contributor

iseki0 commented Jul 5, 2023

Describe the bug
Annotating property type with @Serializable does not override default serializer in typealias. (Just like #1895)
To Reproduce
Attach a code snippet or test data if possible.

import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.serializer


object FooSerializer : KSerializer<A> {
    override val descriptor: SerialDescriptor
        get() = TODO()
    override fun deserialize(decoder: Decoder): A {
        TODO()
    }

    override fun serialize(encoder: Encoder, value: A) {
        TODO("Not yet implemented")
    }
}

@Serializable
data class A(val a: Int)
data class B(val a: Int)
typealias Foo = @Serializable(FooSerializer::class) A
typealias Foooo = @Serializable(FooSerializer::class) B

fun main() {
    println(serializer<Foo>()) // A$$serializer@3b95a09c
    println(serializer<Foooo>()) // FooSerializer@2b05039f
}

Expected behavior
All of them should print FooSerializer@*
Environment

  • Kotlin version: 1.8.22
  • Library version: 1.5.1
  • Kotlin platforms: JVM
  • Gradle version: 8.2
  • IDE version: IntelliJ IDEA 2023.1.2 (Ultimate Edition) Build #IU-231.9011.34, built on May 16, 2023
  • Other relevant context: OpenJDK 17
@iseki0 iseki0 changed the title Annotating property type with @Serializable does not override default serialzer in typealias Annotating property type with @Serializable does not override default serializer in typealias Jul 5, 2023
@sandwwraith
Copy link
Member

Duplicate of #2264. In reality, Kotlin compiler expands typealiases before call, so serialization plugin is unable to do anything.

@sandwwraith sandwwraith closed this as not planned Won't fix, can't repro, duplicate, stale Jul 7, 2023
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