blob: 9d35a290400e093802650cfca5c7082dcc3e9c51 (
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
28
29
30
31
32
33
34
35
36
|
/*
* Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.serialization.features
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.modules.*
import kotlin.test.*
class DefaultPolymorphicSerializerTest : JsonTestBase() {
@Serializable
abstract class Project {
abstract val name: String
}
@Serializable
data class DefaultProject(override val name: String, val type: String): Project()
val module = SerializersModule {
polymorphic(Project::class) {
defaultDeserializer { DefaultProject.serializer() }
}
}
private val json = Json { serializersModule = module }
@Test
fun test() = parametrizedTest {
assertEquals(
DefaultProject("example", "unknown"),
json.decodeFromString<Project>(""" {"type":"unknown","name":"example"}""", it))
}
}
|