Skip to content

Serialization of value classes implementing an interface uses underlying type of value class for array polymorphism #230

Description

@NilsWild

When a value class object is serialized the unterlying type is used. If the value class implments an interface, array polymorphism is used to store the type. However the type is set to the underlying type instead of the value class type. I am not sure if it's possible to fix this or how as the value classes are inlined.

Example:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME)
sealed interface Printable {
    fun prettyPrint(): String
}

@JvmInline
value class Name(val s: String) : Printable {
    override fun prettyPrint(): String = "Let's $s!"
}

A Name object gets serialized to
["String","name"]
when deserializing it can not be mapped for obvious reasons.
Providing ["Name","name"] on the other hand can be deserialized. So the issue is only with serialization.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions