blob: e2d829772a39940d34651f52b8497e0068a1b01d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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 { useStreaming ->
val v1 = Var("a")
val s1 = strict.stringify(Var.serializer(), v1, useStreaming)// {"id":"a"}
assertEquals("""{"id":"a"}""", s1)
val v2: Var = strict.parse(Var.serializer(), s1, useStreaming = true) // should not throw IllegalAccessError
assertEquals(v1, v2)
}
}
|