Skip to content

Value class incompatible with Jackson default typing #608

Closed
@christophejan

Description

@christophejan

Describe the bug

Value class throw exception when Jackson default typing is activated

To Reproduce

data class MyDataClass(val myValue: Any)

@JvmInline
value class MyValueClass(val myValue: String)

val objectMapper = ObjectMapper().apply {
    activateDefaultTyping(polymorphicTypeValidator, DefaultTyping.NON_FINAL, As.PROPERTY)
    registerKotlinModule()
}

objectMapper.writeValueAsString(MyDataClass(MyValueClass("my value")))

Output :

Type id handling not implemented for type java.lang.Object (by serializer of type com.fasterxml.jackson.module.kotlin.ValueClassUnboxSerializer) (through reference chain: fr.maif.epa.backmobile.commons.infrastructure.cache.CacheServiceTest$MyDataClass["myValue"])
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Type id handling not implemented for type java.lang.Object (by serializer of type com.fasterxml.jackson.module.kotlin.ValueClassUnboxSerializer) (through reference chain: fr.maif.epa.backmobile.commons.infrastructure.cache.CacheServiceTest$MyDataClass["myValue"])
	at app//com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77)

Expected behavior

Jackson module Kotlin should be able de serialize/deserialize this kind of value with Jackson default typing

Versions

Kotlin: 1.7.0
Jackson-module-kotlin: 2.13.3
Jackson-databind: 2.13.3

Additional context

Model used to reproduce is a simplified one, just to put in light the current behavior (remove sealed class, complex type in value class etc...).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions