summaryrefslogtreecommitdiff
path: root/runtime/commonTest/src/kotlinx/serialization/json/JsonRootLevelNullTest.kt
blob: 09f8839578e478b9c97127914d69fda34a80fd2e (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.internal.*
import kotlin.test.*

class JsonRootLevelNullTest : JsonTestBase() {

    @Serializable
    private data class Simple(val a: Int = 42)

    @Test
    fun testNullableStringify() {
        // Top-level nulls in tagged encoder is not yet supported, no parametrized test
        val obj: Simple? = null
        val json = strict.stringify(makeNullable(Simple.serializer()), obj)
        assertEquals("null", json)
    }

    @Test
    fun testNullableParse() = parametrizedTest { useStreaming ->
        val result = strict.parse(makeNullable(Simple.serializer()), "null", useStreaming)
        assertNull(result)
    }
}