diff options
Diffstat (limited to 'formats/json-tests/commonTest/src/kotlinx/serialization/json/polymorphic/JsonDeserializePolymorphicTwiceTest.kt')
-rw-r--r-- | formats/json-tests/commonTest/src/kotlinx/serialization/json/polymorphic/JsonDeserializePolymorphicTwiceTest.kt | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/json/polymorphic/JsonDeserializePolymorphicTwiceTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/json/polymorphic/JsonDeserializePolymorphicTwiceTest.kt new file mode 100644 index 00000000..f0229046 --- /dev/null +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/json/polymorphic/JsonDeserializePolymorphicTwiceTest.kt @@ -0,0 +1,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)) + } +}
\ No newline at end of file |