diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 8efe3f38..d2b9c089 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -16,6 +16,9 @@ Authors: Contributors: # 2.18.0 (not yet released) + +WrongWrong (@k163377) +* #817: Fixed nullability of convertValue function argument * #782: Organize deprecated contents * #542: Remove meaningless checks and properties in KNAI diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 4197de12..dd7fa587 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -18,6 +18,7 @@ Co-maintainers: 2.18.0 (not yet released) +#817: The convertValue extension function now accepts null #803: Kotlin has been upgraded to 1.8.10. The reason 1.8.22 is not used is to avoid KT-65156. #782: Content marked as deprecated has been reorganized. diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt index 3e5d1c09..2a8c3b1a 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt @@ -61,7 +61,7 @@ inline fun ObjectMapper.readValue(src: InputStream): T = readValue(s inline fun ObjectMapper.readValue(src: ByteArray): T = readValue(src, jacksonTypeRef()) inline fun ObjectMapper.treeToValue(n: TreeNode): T = readValue(this.treeAsTokens(n), jacksonTypeRef()) -inline fun ObjectMapper.convertValue(from: Any): T = convertValue(from, jacksonTypeRef()) +inline fun ObjectMapper.convertValue(from: Any?): T = convertValue(from, jacksonTypeRef()) inline fun ObjectReader.readValueTyped(jp: JsonParser): T = readValue(jp, jacksonTypeRef()) inline fun ObjectReader.readValuesTyped(jp: JsonParser): Iterator = readValues(jp, jacksonTypeRef()) diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub757.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub757.kt new file mode 100644 index 00000000..558060b3 --- /dev/null +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub757.kt @@ -0,0 +1,22 @@ +package com.fasterxml.jackson.module.kotlin.test.github + +import com.fasterxml.jackson.databind.json.JsonMapper +import com.fasterxml.jackson.module.kotlin.KotlinFeature +import com.fasterxml.jackson.module.kotlin.KotlinModule +import com.fasterxml.jackson.module.kotlin.convertValue +import kotlin.test.Test +import kotlin.test.assertNull + +class GitHub757 { + @Test + fun test() { + val kotlinModule = KotlinModule.Builder() + .enable(KotlinFeature.StrictNullChecks) + .build() + val mapper = JsonMapper.builder() + .addModule(kotlinModule) + .build() + val convertValue = mapper.convertValue(null) + assertNull(convertValue) + } +}