Skip to content

Commit

Permalink
Fix JacksonInject priority
Browse files Browse the repository at this point in the history
fixes #722
  • Loading branch information
k163377 committed Dec 9, 2023
1 parent 0cd8a7e commit c9d7092
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,8 +44,7 @@ class Github722 {
.with(InjectableValues.Std(injectValues))
.readValue<FailingDto>("{}")

assertNotEquals(result, expected, "GitHubXXX fixed.")
assertEquals(FailingDto(), result)
assertEquals(expected, result)
}

data class WithoutDefaultValue(
Expand Down

0 comments on commit c9d7092

Please sign in to comment.