File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
main/kotlin/io/github/projectmapk/jackson/module/kogera/deser/value_instantiator
test/kotlin/io/github/projectmapk/jackson/module/kogera/_ported/test/github Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 11package io.github.projectmapk.jackson.module.kogera.deser.value_instantiator
22
3+ import com.fasterxml.jackson.annotation.Nulls
34import com.fasterxml.jackson.databind.BeanDescription
45import com.fasterxml.jackson.databind.DeserializationConfig
56import com.fasterxml.jackson.databind.DeserializationContext
@@ -33,6 +34,9 @@ internal class KotlinValueInstantiator(
3334 private fun JavaType.requireEmptyValue () =
3435 (nullToEmptyCollection && this .isCollectionLikeType) || (nullToEmptyMap && this .isMapLikeType)
3536
37+ private fun SettableBeanProperty.skipNulls (): Boolean =
38+ nullIsSameAsDefault || (metadata.valueNulls == Nulls .SKIP )
39+
3640 private val valueCreator: ValueCreator <* >? by ReflectProperties .lazySoft {
3741 val creator = _withArgsCreator .annotated as Executable
3842 val jmClass = cache.getJmClass(creator.declaringClass) ? : return @lazySoft null
@@ -65,7 +69,7 @@ internal class KotlinValueInstantiator(
6569
6670 var paramVal = if (! isMissing || paramDef.isPrimitive || jsonProp.hasInjectableValueId()) {
6771 buffer.getParameter(jsonProp).apply {
68- if (nullIsSameAsDefault && this == null && paramDef.isOptional) return @forEachIndexed
72+ if (this == null && jsonProp.skipNulls() && paramDef.isOptional) return @forEachIndexed
6973 }
7074 } else {
7175 if (paramDef.isNullable) {
Original file line number Diff line number Diff line change 1+ package io.github.projectmapk.jackson.module.kogera._ported.test.github
2+
3+ import com.fasterxml.jackson.annotation.JsonSetter
4+ import com.fasterxml.jackson.annotation.Nulls
5+ import io.github.projectmapk.jackson.module.kogera.jacksonObjectMapper
6+ import io.github.projectmapk.jackson.module.kogera.readValue
7+ import org.junit.jupiter.api.Assertions.assertEquals
8+ import org.junit.jupiter.api.Test
9+
10+ class Github526 {
11+ data class D (@JsonSetter(nulls = Nulls .SKIP ) val v : Int = -1 )
12+
13+ @Test
14+ fun test () {
15+ val mapper = jacksonObjectMapper()
16+ val d = mapper.readValue<D >(""" {"v":null}""" )
17+
18+ assertEquals(- 1 , d.v)
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments