File tree Expand file tree Collapse file tree 4 files changed +27
-1
lines changed
main/kotlin/com/fasterxml/jackson/module/kotlin
test/kotlin/com/fasterxml/jackson/module/kotlin/test/github Expand file tree Collapse file tree 4 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ kkurczewski
2121* #689 : Add KotlinDuration support
2222
2323WrongWrong (@k163377 )
24+ * #707 : Changed to use default argument on null if JsonSetter(nulls = Nulls.SKIP) is specified.
2425* #700 : Reduce the load on the search process for serializers
2526* #687 : Optimize and Refactor KotlinValueInstantiator.createFromObjectWith
2627* #686 : Add KotlinPropertyNameAsImplicitName option
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ Co-maintainers:
1818
19192.16 .0 (not yet released )
2020
21+ #707 : If JsonSetter (nulls = Nulls .SKIP ) is specified , the default argument is now used when null .
2122#700 : Reduce the load on the search process for serializers.
2223#689 : Added UseJavaDurationConversion feature.
2324 By enabling this feature and adding the Java Time module , Kotlin Duration can be handled in the same way as Java Duration .
Original file line number Diff line number Diff line change 11package com.fasterxml.jackson.module.kotlin
22
3+ import com.fasterxml.jackson.annotation.Nulls
34import com.fasterxml.jackson.databind.BeanDescription
45import com.fasterxml.jackson.databind.DeserializationConfig
56import com.fasterxml.jackson.databind.DeserializationContext
@@ -32,6 +33,9 @@ internal class KotlinValueInstantiator(
3233
3334 private fun List<KTypeProjection>.markedNonNullAt (index : Int ) = getOrNull(index)?.type?.isMarkedNullable == false
3435
36+ private fun SettableBeanProperty.skipNulls (): Boolean =
37+ nullIsSameAsDefault || (metadata.valueNulls == Nulls .SKIP )
38+
3539 override fun createFromObjectWith (
3640 ctxt : DeserializationContext ,
3741 props : Array <out SettableBeanProperty >,
@@ -70,7 +74,7 @@ internal class KotlinValueInstantiator(
7074 val paramType = paramDef.type
7175 var paramVal = if (! isMissing || paramDef.isPrimitive() || jsonProp.hasInjectableValueId()) {
7276 val tempParamVal = buffer.getParameter(jsonProp)
73- if (nullIsSameAsDefault && tempParamVal == null && paramDef.isOptional) {
77+ if (tempParamVal == null && jsonProp.skipNulls() && paramDef.isOptional) {
7478 return @forEachIndexed
7579 }
7680 tempParamVal
Original file line number Diff line number Diff line change 1+ package com.fasterxml.jackson.module.kotlin.test.github
2+
3+ import com.fasterxml.jackson.annotation.JsonSetter
4+ import com.fasterxml.jackson.annotation.Nulls
5+ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
6+ import com.fasterxml.jackson.module.kotlin.readValue
7+ import org.junit.Test
8+ import kotlin.test.assertEquals
9+
10+ class Github526 {
11+ data class D (@JsonSetter(nulls = Nulls .SKIP ) val v : Int = -1 )
12+
13+ @Test
14+ fun test () {
15+ val mapper = jacksonObjectMapper()
16+ val d = mapper.readValue<D >(""" {"v":null}""" )
17+
18+ assertEquals(- 1 , d.v)
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments