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

Unable to deserialize sealed interface with value class children #2835

Open
Nek-12 opened this issue Oct 14, 2024 · 2 comments
Open

Unable to deserialize sealed interface with value class children #2835

Nek-12 opened this issue Oct 14, 2024 · 2 comments

Comments

@Nek-12
Copy link

Nek-12 commented Oct 14, 2024

This code is impossible to deserialize:

@Serializable
data class EditPromoCodeRequest(
    val code: String? = null,
    val owner: UserQuery? = null,
) 

@Serializable
sealed interface UserQuery {

    @Serializable
    @SerialName("id")
    @JvmInline
    value class Id(val id: UUID) : UserQuery

    @Serializable
    @SerialName("email")
    @JvmInline
    value class Email(val email: String) : UserQuery
}

When a json object is sent, the serialization fails with :

Illegal input: Unexpected JSON token at offset 54: Expected beginning of the string, but got { at path: $.owner

When a string is sent, the request fails with:

Illegal input: Expected JsonObject, but had JsonLiteral as the serialized body of UserQuery at element: $.owner

Example of a correct body:

{
    "owner": {
        "type": "email",
        "email": "[email protected]"
    }
}

Environment

  • Kotlin version: 2.0.20
  • Library version: [e.g. 0.11.0] 1.7.3
  • Kotlin platforms: [e.g. JVM, JS, Native or their combinations] JVM backend
  • Gradle version: [e.g. 4.10] 8.10
@valeriyo
Copy link

I think this is the same issue as #2839

@sandwwraith
Copy link
Member

For context: #2049 (comment)

Perhaps there should be special mode for value classes in this case

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

No branches or pull requests

3 participants