Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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))
}
}