From edf95928e3dc8293b4a78106d8720cfacdb6b12d Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 16 Nov 2024 18:22:28 +0900 Subject: [PATCH] Add check for #844 --- .../module/kotlin/test/github/GitHub844.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub844.kt diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub844.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub844.kt new file mode 100644 index 00000000..7ee202d6 --- /dev/null +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub844.kt @@ -0,0 +1,30 @@ +package com.fasterxml.jackson.module.kotlin.test.github + +import com.fasterxml.jackson.annotation.JsonTypeInfo +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.readValue +import com.fasterxml.jackson.module.kotlin.registerKotlinModule +import kotlin.test.Test +import kotlin.test.assertEquals + +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "_type") +private sealed class BaseClass + +private data class ChildClass(val text: String) : BaseClass() + +class GitHub844 { + @Test + fun test() { + val json = """ + { + "_type": "ChildClass", + "text": "Test" + } + """ + + val jacksonObjectMapper = ObjectMapper().registerKotlinModule() + val message = jacksonObjectMapper.readValue(json) + + assertEquals(ChildClass("Test"), message) + } +}