forked from Kotlin/kotlinx.serialization
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...monTest/src/kotlinx/serialization/features/sealed/SealedInterfacesInlineSerialNameTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"}]""" | ||
) | ||
} | ||
} |