From ab4ba44c5213eb5b77b0efcaa15ed261360bdc11 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 8 Feb 2025 23:17:25 +0900 Subject: [PATCH 1/2] Add test case to serialize Nothing? wrt #314 --- .../module/kotlin/test/github/GitHub314.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub314.kt diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub314.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub314.kt new file mode 100644 index 000000000..c01ef0c84 --- /dev/null +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub314.kt @@ -0,0 +1,29 @@ +package com.fasterxml.jackson.module.kotlin.test.github + +import com.fasterxml.jackson.databind.MapperFeature +import com.fasterxml.jackson.module.kotlin.jsonMapper +import com.fasterxml.jackson.module.kotlin.kotlinModule +import kotlin.test.Test +import kotlin.test.assertEquals + +class GitHub314 { + // Since Nothing? is compiled as a Void, it can be serialized by specifying ALLOW_VOID_VALUED_PROPERTIES + data object NothingData { + val data: Nothing? = null + } + + @Test + fun test() { + val expected = """{"data":null}""" + + val withoutKotlinModule = jsonMapper { enable(MapperFeature.ALLOW_VOID_VALUED_PROPERTIES) } + assertEquals(expected, withoutKotlinModule.writeValueAsString(NothingData)) + + val withKotlinModule = jsonMapper { + enable(MapperFeature.ALLOW_VOID_VALUED_PROPERTIES) + addModule(kotlinModule()) + } + + assertEquals(expected, withKotlinModule.writeValueAsString(NothingData)) + } +} From 66ef70ebce58d5f906f950b570588e54fccf9aeb Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 8 Feb 2025 23:27:22 +0900 Subject: [PATCH 2/2] Update release notes wrt #914 --- release-notes/CREDITS-2.x | 1 + 1 file changed, 1 insertion(+) diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index a408c4e2f..87fb14c78 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -18,6 +18,7 @@ Contributors: # 2.19.0 (not yet released) WrongWrong (@k163377) +* #914: Add test case to serialize Nothing? (for #314) * #910: Add default KeyDeserializer for value class * #885: Performance improvement of strictNullChecks * #884: Changed the base class of MissingKotlinParameterException to InvalidNullException