blob: 6939776499f5b7ad8b16eddf2c7157a5b9888c3c (
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
|
/*
* Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.serialization.json
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.*
import kotlin.test.*
class JsonRootLevelNullTest : JsonTestBase() {
@Serializable
private data class Simple(val a: Int = 42)
@Test
fun testNullableEncode() {
// Top-level nulls in tagged encoder is not yet supported, no parametrized test
val obj: Simple? = null
val json = default.encodeToString(Simple.serializer().nullable, obj)
assertEquals("null", json)
}
@Test
fun testNullableDecode() = parametrizedTest { jsonTestingMode ->
val result = default.decodeFromString(Simple.serializer().nullable, "null", jsonTestingMode)
assertNull(result)
}
}
|