1 /* <lambda>null2 * Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 package kotlinx.serialization.json 6 7 import kotlinx.serialization.Serializable 8 import kotlinx.serialization.builtins.* 9 import kotlin.test.* 10 11 class JsonRootLevelNullTest : JsonTestBase() { 12 13 @Serializable 14 private data class Simple(val a: Int = 42) 15 16 @Test 17 fun testNullableEncode() { 18 // Top-level nulls in tagged encoder is not yet supported, no parametrized test 19 val obj: Simple? = null 20 val json = default.encodeToString(Simple.serializer().nullable, obj) 21 assertEquals("null", json) 22 } 23 24 @Test 25 fun testNullableDecode() = parametrizedTest { jsonTestingMode -> 26 val result = default.decodeFromString(Simple.serializer().nullable, "null", jsonTestingMode) 27 assertNull(result) 28 } 29 } 30