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

External generated sealed class serializer returns empty json. #970

Open
Dominaezzz opened this issue Aug 13, 2020 · 3 comments
Open

External generated sealed class serializer returns empty json. #970

Dominaezzz opened this issue Aug 13, 2020 · 3 comments
Assignees
Labels
bug compiler-plugin External generated serializer Everything related to external auto-generated serializer (@Serializer annotation) Priority: 3

Comments

@Dominaezzz
Copy link
Contributor

Dominaezzz commented Aug 13, 2020

Describe the bug
Serializer returns {} when deserializing

To Reproduce
Attach a code snippet or test data if possible.

    @Serializable(AnimalSerializer::class)
    sealed class Animal {
        @Serializable
        data class Dog(val breed: String) : Animal()
        @Serializable
        data class Cat(val color: String) : Animal()
    }

    @Serializer(forClass = Animal::class)
    object AnimalSerializer

    @Test
    fun testReproduce() {
        println(Json.encodeToString(Animal.serializer(), Animal.Dog("German Shephard")))
    }

Expected behavior

{"type":"io.github.matrixkt.EventTypeTests.Animal.Dog","breed":"German Shephard"} instead of {}

Environment

  • Kotlin version: 1.4.0
  • Library version: 1.0.0-RC
  • Kotlin platforms: At least on JVM.
  • Gradle version: 6.3
  • Other relevant context: Arch Linux, JDK 11
@ganfra
Copy link

ganfra commented Oct 8, 2020

@sandwwraith any news about it?

@sandwwraith
Copy link
Member

External serialization is now considered an experimental feature and it's not a top priority, so I can't tell any particular timeframe for the fix

@Dominaezzz
Copy link
Contributor Author

Rip, that's unfortunate. I was using this as a workaround for #546, by using a JsonTransformingSerializer to rewrite the class discriminator.
I guess I'll use a PolymorphicSerializer for now.

@sandwwraith sandwwraith added the External generated serializer Everything related to external auto-generated serializer (@Serializer annotation) label Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug compiler-plugin External generated serializer Everything related to external auto-generated serializer (@Serializer annotation) Priority: 3
Projects
None yet
Development

No branches or pull requests

4 participants