Skip to content

Commit a6ca97c

Browse files
committed
Fix broken tests for sealed types
1 parent 70f542c commit a6ca97c

2 files changed

Lines changed: 7 additions & 14 deletions

File tree

common/src/main/kotlin/de/sipgate/federmappe/common/decoder/StringMapToObjectDecoder.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@ class StringMapToObjectDecoder(
6363

6464
override fun beginStructure(descriptor: SerialDescriptor): CompositeDecoder {
6565
if (descriptor.kind is PolymorphicKind.SEALED) {
66+
@Suppress("UNCHECKED_CAST")
67+
val source = (if (key != null) data[key] as? StringMap else null) ?: data
6668
return StringMapToObjectDecoder(
67-
data = mapOf(
68-
"type" to data["type"],
69-
"value" to data
70-
),
69+
data = mapOf("type" to source["type"], "value" to source),
7170
serializersModule = serializersModule,
72-
ignoreUnknownProperties = ignoreUnknownProperties
71+
ignoreUnknownProperties = true
7372
)
7473
}
7574

common/src/test/kotlin/de/sipgate/federmappe/common/decoder/SealedTypeTests.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import kotlinx.serialization.ExperimentalSerializationApi
44
import kotlinx.serialization.SerialName
55
import kotlinx.serialization.Serializable
66
import kotlinx.serialization.serializer
7-
import kotlin.test.Ignore
87
import kotlin.test.Test
98
import kotlin.test.assertEquals
109
import kotlin.test.assertIs
1110
import kotlin.test.assertTrue
1211

13-
@Ignore("Fails decoding nested structures")
1412
@OptIn(ExperimentalSerializationApi::class)
1513
internal class SealedTypeTests {
1614

@@ -44,7 +42,7 @@ internal class SealedTypeTests {
4442
val data = mapOf<String, Any?>(
4543
"a" to mapOf(
4644
"type" to "A",
47-
"value" to mapOf("value" to "some string")
45+
"value" to "some string"
4846
)
4947
)
5048

@@ -67,7 +65,7 @@ internal class SealedTypeTests {
6765
val data = mapOf<String, Any?>(
6866
"a" to mapOf(
6967
"type" to "B",
70-
"value" to mapOf("value" to true)
68+
"value" to true
7169
)
7270
)
7371

@@ -90,11 +88,7 @@ internal class SealedTypeTests {
9088
val data = mapOf<String, Any?>(
9189
"a" to mapOf(
9290
"type" to "C",
93-
"value" to mapOf(
94-
"innerValue" to mapOf(
95-
"inner" to "it works!"
96-
)
97-
)
91+
"innerValue" to mapOf("inner" to "it works!")
9892
)
9993
)
10094

0 commit comments

Comments
 (0)