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 4 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ kkurczewski
21
21
* #689 : Add KotlinDuration support
22
22
23
23
WrongWrong (@k163377 )
24
+ * #707 : Changed to use default argument on null if JsonSetter(nulls = Nulls.SKIP) is specified.
24
25
* #700 : Reduce the load on the search process for serializers
25
26
* #687 : Optimize and Refactor KotlinValueInstantiator.createFromObjectWith
26
27
* #686 : Add KotlinPropertyNameAsImplicitName option
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ Co-maintainers:
18
18
19
19
2.16 .0 (not yet released )
20
20
21
+ #707 : If JsonSetter (nulls = Nulls .SKIP ) is specified , the default argument is now used when null .
21
22
#700 : Reduce the load on the search process for serializers.
22
23
#689 : Added UseJavaDurationConversion feature.
23
24
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 1
1
package com.fasterxml.jackson.module.kotlin
2
2
3
+ import com.fasterxml.jackson.annotation.Nulls
3
4
import com.fasterxml.jackson.databind.BeanDescription
4
5
import com.fasterxml.jackson.databind.DeserializationConfig
5
6
import com.fasterxml.jackson.databind.DeserializationContext
@@ -32,6 +33,9 @@ internal class KotlinValueInstantiator(
32
33
33
34
private fun List<KTypeProjection>.markedNonNullAt (index : Int ) = getOrNull(index)?.type?.isMarkedNullable == false
34
35
36
+ private fun SettableBeanProperty.skipNulls (): Boolean =
37
+ nullIsSameAsDefault || (metadata.valueNulls == Nulls .SKIP )
38
+
35
39
override fun createFromObjectWith (
36
40
ctxt : DeserializationContext ,
37
41
props : Array <out SettableBeanProperty >,
@@ -70,7 +74,7 @@ internal class KotlinValueInstantiator(
70
74
val paramType = paramDef.type
71
75
var paramVal = if (! isMissing || paramDef.isPrimitive() || jsonProp.hasInjectableValueId()) {
72
76
val tempParamVal = buffer.getParameter(jsonProp)
73
- if (nullIsSameAsDefault && tempParamVal == null && paramDef.isOptional) {
77
+ if (tempParamVal == null && jsonProp.skipNulls() && paramDef.isOptional) {
74
78
return @forEachIndexed
75
79
}
76
80
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