Skip to content

Commit 9255bf3

Browse files
committed
fix issue with FAIL_ON_NULL_CREATOR_PROPERTIES for collections (#733)
1 parent bfa05dc commit 9255bf3

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/main/java/com/fasterxml/jackson/module/scala/deser/ContainerDeserializerWithNullValueAsEmpty.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.fasterxml.jackson.module.scala.deser;
22

33
import com.fasterxml.jackson.databind.DeserializationContext;
4+
import com.fasterxml.jackson.databind.DeserializationFeature;
45
import com.fasterxml.jackson.databind.JavaType;
56
import com.fasterxml.jackson.databind.JsonMappingException;
67
import com.fasterxml.jackson.databind.deser.std.ContainerDeserializerBase;
@@ -16,6 +17,10 @@ protected ContainerDeserializerWithNullValueAsEmpty(JavaType selfType) {
1617

1718
@Override
1819
public T getNullValue(DeserializationContext ctxt) throws JsonMappingException {
19-
return (T) getEmptyValue(ctxt);
20+
if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES)) {
21+
return super.getNullValue(ctxt);
22+
} else {
23+
return (T) getEmptyValue(ctxt);
24+
}
2025
}
2126
}

src/test/scala/com/fasterxml/jackson/module/scala/deser/CaseClassDeserializerTest.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ class CaseClassDeserializerTest extends DeserializerTest {
207207
result.list shouldBe List.empty
208208
}
209209

210+
it should "fail when deserializing null input for list if FAIL_ON_NULL_CREATOR_PROPERTIES enabled" in {
211+
val input = """{}"""
212+
val mapper = newBuilder.enable(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES).build()
213+
intercept[com.fasterxml.jackson.databind.exc.MismatchedInputException] {
214+
mapper.readValue(input, classOf[ListHolder[String]])
215+
}
216+
}
217+
210218
it should "support deserializing null input for list as empty list (JsonSetter annotation)" in {
211219
val input = """{}"""
212220
val result = deserialize(input, classOf[AnnotatedListHolder[String]])
@@ -231,4 +239,13 @@ class CaseClassDeserializerTest extends DeserializerTest {
231239
// result.map used to be null until v2.19.0
232240
result.map shouldBe Map.empty
233241
}
242+
243+
it should "fail when deserializing null input for map if FAIL_ON_NULL_CREATOR_PROPERTIES enabled" in {
244+
val input = """{}"""
245+
val mapper = newBuilder.enable(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES).build()
246+
intercept[com.fasterxml.jackson.databind.exc.MismatchedInputException] {
247+
mapper.readValue(input, classOf[MapHolder[Int, String]])
248+
}
249+
}
250+
234251
}

0 commit comments

Comments
 (0)