• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.serialization.json
6 
7 import kotlinx.serialization.*
8 import kotlin.test.Test
9 import kotlin.test.assertEquals
10 
11 sealed class Expr
12 
13 @Serializable
14 data class Var(val id: String) : Expr()
15 
16 class JsonSealedSubclassTest : JsonTestBase() {
17 
18     // inspired by kotlinx.serialization/#112
19     @Test
20     fun testCallSuperSealedConstructorProperly() = parametrizedTest { jsonTestingMode ->
21         val v1 = Var("a")
22         val s1 = default.encodeToString(Var.serializer(), v1, jsonTestingMode)// {"id":"a"}
23         assertEquals("""{"id":"a"}""", s1)
24         val v2: Var = default.decodeFromString(Var.serializer(), s1, JsonTestingMode.STREAMING) // should not throw IllegalAccessError
25         assertEquals(v1, v2)
26     }
27 }
28