Skip to content

Commit 842e2ea

Browse files
author
ddomanine
committed
Added more cases that fail: fields with default values and payload with explicit null values
1 parent c7b1c3f commit 842e2ea

File tree

1 file changed

+26
-2
lines changed
  • src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github

1 file changed

+26
-2
lines changed

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class Github490 {
1212
@Test
1313
fun testKotlinDeserialization() {
1414
val mapper = jacksonObjectMapper()
15-
val value: DataClassWithAllNullableParams = mapper.readValue("{}")
15+
val value: DataClassWithAllNullableParams = mapper.readValue("{" +
16+
"\"jsonNodeValueWithNullAsDefaultProvidedNull\":null, " +
17+
"\"jsonNodeValueProvidedNull\":null}")
1618
assertThat(
1719
"Nullable missing Int value should be deserialized as null",
1820
value.intValue,
@@ -28,7 +30,29 @@ class Github490 {
2830
value.jsonNodeValue,
2931
CoreMatchers.nullValue()
3032
)
33+
assertThat(
34+
"Nullable missing JsonNode value should be deserialized as null and not as NullNode",
35+
value.jsonNodeValueProvidedNull,
36+
CoreMatchers.nullValue()
37+
)
38+
assertThat(
39+
"Nullable by default missing JsonNode value should be deserialized as null and not as NullNode",
40+
value.jsonNodeValueWithNullAsDefault,
41+
CoreMatchers.nullValue()
42+
)
43+
assertThat(
44+
"Nullable by default JsonNode with provided null value in payload should be deserialized as null and not as NullNode",
45+
value.jsonNodeValueWithNullAsDefaultProvidedNull,
46+
CoreMatchers.nullValue()
47+
)
3148
}
3249
}
3350

34-
data class DataClassWithAllNullableParams(val intValue: Int?, val stringValue: String?, val jsonNodeValue: JsonNode?)
51+
data class DataClassWithAllNullableParams(
52+
val intValue: Int?,
53+
val stringValue: String?,
54+
val jsonNodeValue: JsonNode?,
55+
val jsonNodeValueProvidedNull: JsonNode?,
56+
val jsonNodeValueWithNullAsDefault: JsonNode? = null,
57+
val jsonNodeValueWithNullAsDefaultProvidedNull: JsonNode? = null
58+
)

0 commit comments

Comments
 (0)