```import com.fasterxml.jackson.annotation.JsonUnw...
# jackson-kotlin
r
Copy code
import com.fasterxml.jackson.annotation.JsonUnwrapped
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

data class Container(@JsonUnwrapped val row: Map<String, Any?>)

class JsonUnwrappedTest {

    @Test
    fun `should unwrap`() {
        val row = Container(row = mapOf("foo" to "bar"))

        val objectMapper = ObjectMapper()
        objectMapper.registerModule(KotlinModule())

        val json = objectMapper.writeValueAsString(row)
        assertThat(json).isEqualTo("""{"foo": "bar"}""") // fails
    }
}
d
This has nothing to do with Kotlin.
JsonUnwrapped
only works for POJOs, not Maps. You can use a combination of
JsonAnyGetter
and
JsonAnySetter
to achieve something similar, seen here: https://stackoverflow.com/a/18043785
r
@diesieben07 oh, thanks a lot. I wasn’t aware of this