All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonTest.kotlinx.serialization.json.JsonRootLevelNullTest.kt Maven / Gradle / Ivy

There is a newer version: 1.7.3
Show newest version
/*
 * 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)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy