Skip to content

Commit

Permalink
Merge remote-tracking branch 'FasterXML/2.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
k163377 committed Sep 2, 2023
2 parents 8c26a3a + 05955a4 commit d6053da
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ kkurczewski
* #689: Add KotlinDuration support

WrongWrong (@k163377)
* #707: Changed to use default argument on null if JsonSetter(nulls = Nulls.SKIP) is specified.
* #700: Reduce the load on the search process for serializers
* #687: Optimize and Refactor KotlinValueInstantiator.createFromObjectWith
* #686: Add KotlinPropertyNameAsImplicitName option
Expand Down
1 change: 1 addition & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Co-maintainers:

2.16.0 (not yet released)

#707: If JsonSetter(nulls = Nulls.SKIP) is specified, the default argument is now used when null.
#700: Reduce the load on the search process for serializers.
#689: Added UseJavaDurationConversion feature.
By enabling this feature and adding the Java Time module, Kotlin Duration can be handled in the same way as Java Duration.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tools.jackson.module.kotlin

import com.fasterxml.jackson.annotation.Nulls
import tools.jackson.databind.BeanDescription
import tools.jackson.databind.DeserializationConfig
import tools.jackson.databind.DeserializationContext
Expand Down Expand Up @@ -32,6 +33,9 @@ internal class KotlinValueInstantiator(

private fun List<KTypeProjection>.markedNonNullAt(index: Int) = getOrNull(index)?.type?.isMarkedNullable == false

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

override fun createFromObjectWith(
ctxt: DeserializationContext,
props: Array<out SettableBeanProperty>,
Expand Down Expand Up @@ -70,12 +74,12 @@ internal class KotlinValueInstantiator(
val paramType = paramDef.type
var paramVal = if (!isMissing || paramDef.isPrimitive() || jsonProp.hasInjectableValueId()) {
val tempParamVal = buffer.getParameter(jsonProp)
if (nullIsSameAsDefault && tempParamVal == null && paramDef.isOptional) {
if (tempParamVal == null && jsonProp.skipNulls() && paramDef.isOptional) {
return@forEachIndexed
}
tempParamVal
} else {
if(paramType.isMarkedNullable) {
if (paramType.isMarkedNullable) {
// do not try to create any object if it is nullable and the value is missing
null
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tools.jackson.module.kotlin.test.github

import com.fasterxml.jackson.annotation.JsonSetter
import com.fasterxml.jackson.annotation.Nulls
import org.junit.Test
import tools.jackson.module.kotlin.jacksonObjectMapper
import tools.jackson.module.kotlin.readValue
import kotlin.test.assertEquals

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)
}
}

0 comments on commit d6053da

Please sign in to comment.