summaryrefslogtreecommitdiff
path: root/formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonSealedSubclassTest.kt
diff options
context:
space:
mode:
Diffstat (limited to 'formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonSealedSubclassTest.kt')
-rw-r--r--formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonSealedSubclassTest.kt27
1 files changed, 27 insertions, 0 deletions
diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonSealedSubclassTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonSealedSubclassTest.kt
new file mode 100644
index 00000000..5fac878d
--- /dev/null
+++ b/formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonSealedSubclassTest.kt
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ */
+
+package kotlinx.serialization.json
+
+import kotlinx.serialization.*
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+sealed class Expr
+
+@Serializable
+data class Var(val id: String) : Expr()
+
+class JsonSealedSubclassTest : JsonTestBase() {
+
+ // inspired by kotlinx.serialization/#112
+ @Test
+ fun testCallSuperSealedConstructorProperly() = parametrizedTest { jsonTestingMode ->
+ val v1 = Var("a")
+ val s1 = default.encodeToString(Var.serializer(), v1, jsonTestingMode)// {"id":"a"}
+ assertEquals("""{"id":"a"}""", s1)
+ val v2: Var = default.decodeFromString(Var.serializer(), s1, JsonTestingMode.STREAMING) // should not throw IllegalAccessError
+ assertEquals(v1, v2)
+ }
+}