Skip to content

Commit e48cfb4

Browse files
authored
Merge pull request #817 from k163377/fix/757
Fixed nullability of `convertValue` function argument
2 parents b0eab85 + 54a3fc5 commit e48cfb4

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

release-notes/CREDITS-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Authors:
1616
Contributors:
1717

1818
# 2.18.0 (not yet released)
19+
20+
WrongWrong (@k163377)
21+
* #817: Fixed nullability of convertValue function argument
1922
* #782: Organize deprecated contents
2023
* #542: Remove meaningless checks and properties in KNAI
2124

release-notes/VERSION-2.x

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Co-maintainers:
1818

1919
2.18.0 (not yet released)
2020

21+
#817: The convertValue extension function now accepts null
2122
#803: Kotlin has been upgraded to 1.8.10.
2223
The reason 1.8.22 is not used is to avoid KT-65156.
2324
#782: Content marked as deprecated has been reorganized.

src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ inline fun <reified T> ObjectMapper.readValue(src: InputStream): T = readValue(s
6161
inline fun <reified T> ObjectMapper.readValue(src: ByteArray): T = readValue(src, jacksonTypeRef<T>())
6262

6363
inline fun <reified T> ObjectMapper.treeToValue(n: TreeNode): T = readValue(this.treeAsTokens(n), jacksonTypeRef<T>())
64-
inline fun <reified T> ObjectMapper.convertValue(from: Any): T = convertValue(from, jacksonTypeRef<T>())
64+
inline fun <reified T> ObjectMapper.convertValue(from: Any?): T = convertValue(from, jacksonTypeRef<T>())
6565

6666
inline fun <reified T> ObjectReader.readValueTyped(jp: JsonParser): T = readValue(jp, jacksonTypeRef<T>())
6767
inline fun <reified T> ObjectReader.readValuesTyped(jp: JsonParser): Iterator<T> = readValues(jp, jacksonTypeRef<T>())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fasterxml.jackson.module.kotlin.test.github
2+
3+
import com.fasterxml.jackson.databind.json.JsonMapper
4+
import com.fasterxml.jackson.module.kotlin.KotlinFeature
5+
import com.fasterxml.jackson.module.kotlin.KotlinModule
6+
import com.fasterxml.jackson.module.kotlin.convertValue
7+
import kotlin.test.Test
8+
import kotlin.test.assertNull
9+
10+
class GitHub757 {
11+
@Test
12+
fun test() {
13+
val kotlinModule = KotlinModule.Builder()
14+
.enable(KotlinFeature.StrictNullChecks)
15+
.build()
16+
val mapper = JsonMapper.builder()
17+
.addModule(kotlinModule)
18+
.build()
19+
val convertValue = mapper.convertValue<String?>(null)
20+
assertNull(convertValue)
21+
}
22+
}

0 commit comments

Comments
 (0)