Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed nullability of convertValue function argument #817

Merged
merged 3 commits into from
Jul 6, 2024
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
3 changes: 3 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ inline fun <reified T> ObjectMapper.readValue(src: InputStream): T = readValue(s
inline fun <reified T> ObjectMapper.readValue(src: ByteArray): T = readValue(src, jacksonTypeRef<T>())

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

inline fun <reified T> ObjectReader.readValueTyped(jp: JsonParser): T = readValue(jp, jacksonTypeRef<T>())
inline fun <reified T> ObjectReader.readValuesTyped(jp: JsonParser): Iterator<T> = readValues(jp, jacksonTypeRef<T>())
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String?>(null)
assertNull(convertValue)
}
}