From debaa5e987a364a2ce1234cde33eab424456a192 Mon Sep 17 00:00:00 2001 From: Tad Fisher Date: Wed, 13 Mar 2024 14:36:58 -0700 Subject: [PATCH] Add test for #2288 --- .../SealedInterfacesInlineSerialNameTest.kt | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 formats/json-tests/commonTest/src/kotlinx/serialization/features/sealed/SealedInterfacesInlineSerialNameTest.kt diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/features/sealed/SealedInterfacesInlineSerialNameTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/features/sealed/SealedInterfacesInlineSerialNameTest.kt new file mode 100644 index 000000000..c6f07b12e --- /dev/null +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/features/sealed/SealedInterfacesInlineSerialNameTest.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +package kotlinx.serialization.features.sealed + +import kotlinx.serialization.* +import kotlinx.serialization.json.* +import kotlin.jvm.* +import kotlin.test.* + +class SealedInterfacesInlineSerialNameTest : JsonTestBase() { + @Serializable + data class Child1Value( + val a: Int, + val b: String + ) + + @Serializable + data class Child2Value( + val c: Int, + val d: String + ) + + @Serializable + sealed interface Parent + + @Serializable + @SerialName("child1") + @JvmInline + value class Child1(val value: Child1Value) : Parent + + @Serializable + @SerialName("child2") + @JvmInline + value class Child2(val value: Child2Value) : Parent + + @Test + @Ignore // https://github.com/Kotlin/kotlinx.serialization/issues/2288 + fun testSealedInterfaceInlineSerialName() { + val messages = listOf( + Child1(Child1Value(1, "one")), + Child2(Child2Value(2, "two")) + ) + assertJsonFormAndRestored( + serializer(), + messages, + """[{"type":"child1","a":1,"b":"one"},{"type":"child2","c":2,"d":"two"}]""" + ) + } +}