blob: 76634bbc89c2c0611675e417dcba43f5376b5e8d (
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
class JsonUnionEnumTest : JsonTestBase() {
enum class SomeEnum { ALPHA, BETA, GAMMA }
@Serializable
data class WithUnions(val s: String,
val e: SomeEnum = SomeEnum.ALPHA,
val i: Int = 42)
@Test
fun testEnum() = parametrizedTest { jsonTestingMode ->
val data = WithUnions("foo", SomeEnum.BETA)
val json = default.encodeToString(WithUnions.serializer(), data, jsonTestingMode)
val restored = default.decodeFromString(WithUnions.serializer(), json, jsonTestingMode)
assertEquals(data, restored)
}
}
|