Skip to content

Cannot Construct Subtype of Sealed Class #844

Closed
@skvariljan

Description

@skvariljan

Search before asking

  • I searched in the issues and found nothing similar.
  • I have confirmed that the same problem is not reproduced if I exclude the KotlinModule.
  • I searched in the issues of databind and other modules used and found nothing similar.
  • I have confirmed that the problem does not reproduce in Java and only occurs when using Kotlin and KotlinModule.

Describe the bug

After upgrading from v2.17.2 to v2.18.1, we cannot parse sealed hierarchies annotated with @JsonTypeInfo anymore. The code in the example works in v2.17.2, but doesn't work in later versions and produces the following exception:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of ChildClass (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)

To Reproduce

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "_type")
sealed class BaseClass

data class ChildClass(val text: String) : BaseClass()

val json =
    """
        {
            "_type": "ChildClass",
            "text": "Test"
        }
    """

val jacksonObjectMapper = ObjectMapper().registerKotlinModule()
val message = jacksonObjectMapper.readValue<BaseClass>(json)

println(message is ChildClass)

Expected behavior

Prints true.

Versions

Kotlin:
Jackson-module-kotlin: 2.18.1
Jackson-databind: 2.18.1

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions