-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from ProjectMapK/fix-strict-null-check
Fixed problem with deserialization failing for correct collections when StrictNullCkecks is enabled.
- Loading branch information
Showing
3 changed files
with
98 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...est/kotlin/com/fasterxml/jackson/module/kotlin/_integration/deser/StrictNullChecksTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.fasterxml.jackson.module.kotlin._integration.deser | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.KotlinFeature | ||
import com.fasterxml.jackson.module.kotlin.KotlinModule | ||
import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import org.junit.jupiter.api.Assertions.assertArrayEquals | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Nested | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
|
||
class StrictNullChecksTest { | ||
val mapper: ObjectMapper = ObjectMapper() | ||
.registerModule( | ||
KotlinModule.Builder() | ||
.enable(KotlinFeature.StrictNullChecks) | ||
.build() | ||
) | ||
|
||
class ArrayWrapper(val value: Array<Int>) | ||
data class ListWrapper(val value: List<Int>) | ||
data class MapWrapper(val value: Map<String, Int>) | ||
|
||
@Nested | ||
inner class NonNullInput { | ||
@Test | ||
fun array() { | ||
val expected = ArrayWrapper(arrayOf(1)) | ||
val src = mapper.writeValueAsString(expected) | ||
val result = mapper.readValue<ArrayWrapper>(src) | ||
|
||
assertArrayEquals(expected.value, result.value) | ||
} | ||
|
||
@Test | ||
fun list() { | ||
val expected = ListWrapper(listOf(1)) | ||
val src = mapper.writeValueAsString(expected) | ||
val result = mapper.readValue<ListWrapper>(src) | ||
|
||
assertEquals(expected, result) | ||
} | ||
|
||
@Test | ||
fun map() { | ||
val expected = MapWrapper(mapOf("foo" to 1)) | ||
val src = mapper.writeValueAsString(expected) | ||
val result = mapper.readValue<MapWrapper>(src) | ||
|
||
assertEquals(expected, result) | ||
} | ||
} | ||
|
||
data class AnyWrapper(val value: Any) | ||
|
||
@Nested | ||
inner class NullInput { | ||
@Test | ||
fun array() { | ||
val src = mapper.writeValueAsString(AnyWrapper(arrayOf<Int?>(null))) | ||
assertThrows<MissingKotlinParameterException> { mapper.readValue<ArrayWrapper>(src) } | ||
} | ||
|
||
@Test | ||
fun list() { | ||
val src = mapper.writeValueAsString(AnyWrapper(arrayOf<Int?>(null))) | ||
assertThrows<MissingKotlinParameterException> { mapper.readValue<ListWrapper>(src) } | ||
} | ||
|
||
@Test | ||
fun map() { | ||
val src = mapper.writeValueAsString(AnyWrapper(mapOf("foo" to null))) | ||
assertThrows<MissingKotlinParameterException> { mapper.readValue<MapWrapper>(src) } | ||
} | ||
} | ||
} |