Skip to content

Commit c9d7092

Browse files
committed
Fix JacksonInject priority
fixes #722
1 parent 0cd8a7e commit c9d7092

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinValueInstantiator.kt

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import com.fasterxml.jackson.databind.deser.ValueInstantiators
1111
import com.fasterxml.jackson.databind.deser.impl.NullsAsEmptyProvider
1212
import com.fasterxml.jackson.databind.deser.impl.PropertyValueBuffer
1313
import com.fasterxml.jackson.databind.deser.std.StdValueInstantiator
14-
import com.fasterxml.jackson.databind.exc.MismatchedInputException
1514
import java.lang.reflect.TypeVariable
1615
import kotlin.reflect.KParameter
1716
import kotlin.reflect.KType
@@ -67,24 +66,20 @@ internal class KotlinValueInstantiator(
6766
val jsonProp = props[idx]
6867
val isMissing = !buffer.hasParameter(jsonProp)
6968

70-
if (isMissing && paramDef.isOptional) {
71-
return@forEachIndexed
72-
}
73-
7469
val paramType = paramDef.type
75-
var paramVal = if (!isMissing || paramDef.isPrimitive() || jsonProp.hasInjectableValueId()) {
70+
var paramVal = if (!isMissing || jsonProp.hasInjectableValueId()) {
7671
val tempParamVal = buffer.getParameter(jsonProp)
7772
if (tempParamVal == null && jsonProp.skipNulls() && paramDef.isOptional) {
7873
return@forEachIndexed
7974
}
8075
tempParamVal
8176
} else {
82-
if(paramType.isMarkedNullable) {
77+
when {
78+
paramDef.isOptional -> return@forEachIndexed
8379
// do not try to create any object if it is nullable and the value is missing
84-
null
85-
} else {
80+
paramType.isMarkedNullable -> null
8681
// to get suitable "missing" value provided by deserializer
87-
jsonProp.valueDeserializer?.getAbsentValue(ctxt)
82+
else -> jsonProp.valueDeserializer?.getAbsentValue(ctxt)
8883
}
8984
}
9085

@@ -157,13 +152,6 @@ internal class KotlinValueInstantiator(
157152

158153
}
159154

160-
private fun KParameter.isPrimitive(): Boolean {
161-
return when (val javaType = type.javaType) {
162-
is Class<*> -> javaType.isPrimitive
163-
else -> false
164-
}
165-
}
166-
167155
private fun SettableBeanProperty.hasInjectableValueId(): Boolean = injectableValueId != null
168156
}
169157

src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github722.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonProperty
66
import com.fasterxml.jackson.databind.InjectableValues
77
import com.fasterxml.jackson.databind.ObjectMapper
88
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
9+
import kotlin.math.exp
910
import kotlin.test.Test
1011
import kotlin.test.assertEquals
1112
import kotlin.test.assertNotEquals
@@ -43,8 +44,7 @@ class Github722 {
4344
.with(InjectableValues.Std(injectValues))
4445
.readValue<FailingDto>("{}")
4546

46-
assertNotEquals(result, expected, "GitHubXXX fixed.")
47-
assertEquals(FailingDto(), result)
47+
assertEquals(expected, result)
4848
}
4949

5050
data class WithoutDefaultValue(

0 commit comments

Comments
 (0)