summaryrefslogtreecommitdiff
path: root/formats/json-tests/commonTest/src/kotlinx/serialization/json/polymorphic/JsonDeserializePolymorphicTwiceTest.kt
blob: f0229046981b0047ec1895197516e893337a76c6 (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
/*
 * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package kotlinx.serialization.json.polymorphic

import kotlinx.serialization.Serializable
import kotlinx.serialization.json.*
import kotlin.test.*

class JsonDeserializePolymorphicTwiceTest {

    @Serializable
    sealed class Foo {
        @Serializable
        data class Bar(val a: Int) : Foo()
    }

    @Test
    fun testDeserializeTwice() { // #812
        val json = Json.encodeToJsonElement(Foo.serializer(), Foo.Bar(1))
        assertEquals(Foo.Bar(1), Json.decodeFromJsonElement(Foo.serializer(), json))
        assertEquals(Foo.Bar(1), Json.decodeFromJsonElement(Foo.serializer(), json))
    }
}