Skip to content

Commit d83fe73

Browse files
committed
test: add test for error when invalid type used in serializing
Associated issue: [issue-2938](Kotlin#2938)
1 parent 71b38d9 commit d83fe73

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2017-2025 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.serialization.json.polymorphic
6+
7+
import kotlinx.serialization.json.Json
8+
import kotlin.jvm.JvmInline
9+
import kotlin.test.Test
10+
import kotlin.test.assertFailsWith
11+
12+
class InvalidPolymorphicTypeTest {
13+
sealed interface InvalidType
14+
enum class InvalidEnum : InvalidType {
15+
A, B
16+
}
17+
@JvmInline
18+
value class InvalidInline(val value: Int) : InvalidType
19+
20+
@Test
21+
fun invalidEnum() {
22+
assertFailsWith<IllegalArgumentException> {
23+
Json.encodeToString<InvalidType>(InvalidEnum.A)
24+
}
25+
}
26+
27+
@Test
28+
fun invalidInline() {
29+
assertFailsWith<IllegalArgumentException> {
30+
Json.encodeToString<InvalidType>(InvalidInline(1))
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)