Skip to content

Commit 006d41c

Browse files
committed
fix issue with FAIL_ON_NULL_CREATOR_PROPERTIES for collections
1 parent e0e127c commit 006d41c

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
@@ -206,6 +206,14 @@ class CaseClassDeserializerTest extends DeserializerTest {
206206
result.list shouldBe List.empty
207207
}
208208

209+
it should "fail when deserializing null input for list if FAIL_ON_NULL_CREATOR_PROPERTIES enabled" in {
210+
val input = """{}"""
211+
val mapper = newBuilder.enable(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES).build()
212+
intercept[com.fasterxml.jackson.databind.exc.MismatchedInputException] {
213+
mapper.readValue(input, classOf[ListHolder[String]])
214+
}
215+
}
216+
209217
it should "support deserializing null input for list as empty list (JsonSetter annotation)" in {
210218
val input = """{}"""
211219
val result = deserialize(input, classOf[AnnotatedListHolder[String]])
@@ -218,4 +226,13 @@ class CaseClassDeserializerTest extends DeserializerTest {
218226
// result.map used to be null until v2.19.0
219227
result.map shouldBe Map.empty
220228
}
229+
230+
it should "fail when deserializing null input for map if FAIL_ON_NULL_CREATOR_PROPERTIES enabled" in {
231+
val input = """{}"""
232+
val mapper = newBuilder.enable(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES).build()
233+
intercept[com.fasterxml.jackson.databind.exc.MismatchedInputException] {
234+
mapper.readValue(input, classOf[MapHolder[Int, String]])
235+
}
236+
}
237+
221238
}

0 commit comments

Comments
 (0)