diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinValueInstantiator.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinValueInstantiator.kt index 8c473717..bc167abc 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinValueInstantiator.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinValueInstantiator.kt @@ -11,7 +11,6 @@ import com.fasterxml.jackson.databind.deser.ValueInstantiators import com.fasterxml.jackson.databind.deser.impl.NullsAsEmptyProvider import com.fasterxml.jackson.databind.deser.impl.PropertyValueBuffer import com.fasterxml.jackson.databind.deser.std.StdValueInstantiator -import com.fasterxml.jackson.databind.exc.MismatchedInputException import java.lang.reflect.TypeVariable import kotlin.reflect.KParameter import kotlin.reflect.KType @@ -67,24 +66,20 @@ internal class KotlinValueInstantiator( val jsonProp = props[idx] val isMissing = !buffer.hasParameter(jsonProp) - if (isMissing && paramDef.isOptional) { - return@forEachIndexed - } - val paramType = paramDef.type - var paramVal = if (!isMissing || paramDef.isPrimitive() || jsonProp.hasInjectableValueId()) { + var paramVal = if (!isMissing || jsonProp.hasInjectableValueId()) { val tempParamVal = buffer.getParameter(jsonProp) if (tempParamVal == null && jsonProp.skipNulls() && paramDef.isOptional) { return@forEachIndexed } tempParamVal } else { - if(paramType.isMarkedNullable) { + when { + paramDef.isOptional -> return@forEachIndexed // do not try to create any object if it is nullable and the value is missing - null - } else { + paramType.isMarkedNullable -> null // to get suitable "missing" value provided by deserializer - jsonProp.valueDeserializer?.getAbsentValue(ctxt) + else -> jsonProp.valueDeserializer?.getAbsentValue(ctxt) } } @@ -157,13 +152,6 @@ internal class KotlinValueInstantiator( } - private fun KParameter.isPrimitive(): Boolean { - return when (val javaType = type.javaType) { - is Class<*> -> javaType.isPrimitive - else -> false - } - } - private fun SettableBeanProperty.hasInjectableValueId(): Boolean = injectableValueId != null } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github722.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github722.kt index 483f1caa..344abb3d 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github722.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github722.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.databind.InjectableValues import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import kotlin.math.exp import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals @@ -43,8 +44,7 @@ class Github722 { .with(InjectableValues.Std(injectValues)) .readValue("{}") - assertNotEquals(result, expected, "GitHubXXX fixed.") - assertEquals(FailingDto(), result) + assertEquals(expected, result) } data class WithoutDefaultValue(