Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.projectmapk.jackson.module.kogera.deser.value_instantiator

import com.fasterxml.jackson.annotation.Nulls
import com.fasterxml.jackson.databind.BeanDescription
import com.fasterxml.jackson.databind.DeserializationConfig
import com.fasterxml.jackson.databind.DeserializationContext
Expand Down Expand Up @@ -33,6 +34,9 @@ internal class KotlinValueInstantiator(
private fun JavaType.requireEmptyValue() =
(nullToEmptyCollection && this.isCollectionLikeType) || (nullToEmptyMap && this.isMapLikeType)

private fun SettableBeanProperty.skipNulls(): Boolean =
nullIsSameAsDefault || (metadata.valueNulls == Nulls.SKIP)

private val valueCreator: ValueCreator<*>? by ReflectProperties.lazySoft {
val creator = _withArgsCreator.annotated as Executable
val jmClass = cache.getJmClass(creator.declaringClass) ?: return@lazySoft null
Expand Down Expand Up @@ -65,7 +69,7 @@ internal class KotlinValueInstantiator(

var paramVal = if (!isMissing || paramDef.isPrimitive || jsonProp.hasInjectableValueId()) {
buffer.getParameter(jsonProp).apply {
if (nullIsSameAsDefault && this == null && paramDef.isOptional) return@forEachIndexed
if (this == null && jsonProp.skipNulls() && paramDef.isOptional) return@forEachIndexed
}
} else {
if (paramDef.isNullable) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.github.projectmapk.jackson.module.kogera._ported.test.github

import com.fasterxml.jackson.annotation.JsonSetter
import com.fasterxml.jackson.annotation.Nulls
import io.github.projectmapk.jackson.module.kogera.jacksonObjectMapper
import io.github.projectmapk.jackson.module.kogera.readValue
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class Github526 {
data class D(@JsonSetter(nulls = Nulls.SKIP) val v: Int = -1)

@Test
fun test() {
val mapper = jacksonObjectMapper()
val d = mapper.readValue<D>("""{"v":null}""")

assertEquals(-1, d.v)
}
}