Skip to content

Commit c0a2258

Browse files
committed
~move generic override test directly into kotlinx-serialization test suite
1 parent 57aa964 commit c0a2258

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.serialization
6+
7+
import kotlinx.serialization.builtins.serializer
8+
import kotlinx.serialization.json.*
9+
import kotlin.test.Test
10+
11+
class GenericOverrideTest: JsonTestBase() {
12+
13+
@Serializable
14+
sealed class TypedSealedClass<T>(val a: T) {
15+
@Serializable
16+
@SerialName("child")
17+
data class Child(val y: Int) : TypedSealedClass<String>("10") {
18+
override fun toString(): String = "Child($a, $y)"
19+
}
20+
}
21+
22+
@Test
23+
fun testAinChildSerializesAsString() = parametrizedTest { mode ->
24+
val encodedChild = """{"a":"10","y":42}"""
25+
assertJsonFormAndRestored(TypedSealedClass.Child.serializer(), TypedSealedClass.Child(42), encodedChild)
26+
}
27+
28+
@Test
29+
fun testSerializeAsBaseClass() = parametrizedTest { mode ->
30+
val encodedChild = """{"type":"child","a":"10","y":42}"""
31+
assertJsonFormAndRestored(TypedSealedClass.serializer(String.serializer()), TypedSealedClass.Child(42), encodedChild)
32+
}
33+
}

integration-test/src/commonMain/kotlin/sample/MultiFileHierarchyModuleA.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@ open class GenericBox<E> {
3434
var contents: Map<String, E>? = null
3535
}
3636

37-
// From #1264
38-
@Serializable
39-
sealed class TypedSealedClass<T>(val a: T) {
40-
@Serializable
41-
class Child(val y: Int) : TypedSealedClass<String>("10") {
42-
override fun toString(): String = "Child($a, $y)"
43-
}
44-
}
45-
4637
// From #KT-43910
4738
@Serializable
4839
open class ValidatableValue<T : Any, V: Any>(

integration-test/src/commonTest/kotlin/sample/MultiFileHierarchyTest.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,6 @@ class AbstractBaseTest {
7575
assertStringFormAndRestored("""{"b":"val b","a":"val a","c":"val c"}""", NotInConstructorTest(), NotInConstructorTest.serializer())
7676
}
7777

78-
@Test
79-
fun testSimpleChild() {
80-
val encodedChild = """{"a":"11","y":42}"""
81-
val decodedChild = Json.decodeFromString<TypedSealedClass.Child>(encodedChild)
82-
assertEquals("Child(11, 42)", decodedChild.toString())
83-
assertEquals(encodedChild, Json.encodeToString(decodedChild))
84-
}
85-
8678
@Test
8779
fun testDoubleGeneric() {
8880
val email = Email<Int>().apply {

0 commit comments

Comments
 (0)