File tree 1 file changed +33
-0
lines changed
formats/json-tests/commonTest/src/kotlinx/serialization/json/polymorphic
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments