Skip to content

Commit ece4c8a

Browse files
committed
fix issue with FAIL_ON_NULL_CREATOR_PROPERTIES for collections
1 parent a0fd48b commit ece4c8a

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/main/scala/tools/jackson/module/scala/deser/GenericFactoryDeserializerResolver.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ abstract class GenericFactoryDeserializerResolver[CC[_], CF[X[_]]](config: Scala
145145
bw.builder.result().asInstanceOf[Object]
146146
}
147147

148-
override def getNullValue(ctxt: DeserializationContext): Object = getEmptyValue(ctxt)
148+
override def getNullValue(ctxt: DeserializationContext): Object = {
149+
if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES))
150+
super.getNullValue(ctxt)
151+
else
152+
getEmptyValue(ctxt)
153+
}
149154

150155
private def newBuilderWrapper(ctxt: DeserializationContext): BuilderWrapper[AnyRef] = {
151156
containerDeserializer.getValueInstantiator.createUsingDefault(ctxt).asInstanceOf[BuilderWrapper[AnyRef]]

src/main/scala/tools/jackson/module/scala/deser/GenericMapFactoryDeserializerResolver.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,12 @@ abstract class GenericMapFactoryDeserializerResolver[CC[K, V], CF[X[_, _]]](conf
166166
bw.builder.result().asInstanceOf[Object]
167167
}
168168

169-
override def getNullValue(ctxt: DeserializationContext): Object = getEmptyValue(ctxt)
169+
override def getNullValue(ctxt: DeserializationContext): Object = {
170+
if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES))
171+
super.getNullValue(ctxt)
172+
else
173+
getEmptyValue(ctxt)
174+
}
170175

171176
private def newBuilderWrapper(ctxt: DeserializationContext): BuilderWrapper[AnyRef, AnyRef] = {
172177
containerDeserializer.getValueInstantiator.createUsingDefault(ctxt).asInstanceOf[BuilderWrapper[AnyRef, AnyRef]]

src/test/scala/tools/jackson/module/scala/deser/CaseClassDeserializerTest.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ class CaseClassDeserializerTest extends DeserializerTest {
210210
result.list shouldBe List.empty
211211
}
212212

213+
it should "fail when deserializing null input for list if FAIL_ON_NULL_CREATOR_PROPERTIES enabled" in {
214+
val input = """{}"""
215+
val mapper = newBuilder.enable(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES).build()
216+
intercept[com.fasterxml.jackson.databind.exc.MismatchedInputException] {
217+
mapper.readValue(input, classOf[ListHolder[String]])
218+
}
219+
}
220+
213221
it should "support deserializing null input for list as empty list (JsonSetter annotation)" in {
214222
val input = """{}"""
215223
val result = deserialize(input, classOf[AnnotatedListHolder[String]])
@@ -240,4 +248,12 @@ class CaseClassDeserializerTest extends DeserializerTest {
240248
val result = deserialize(input, classOf[AnnotatedMapHolder[Int, String]])
241249
result.map shouldBe Map.empty
242250
}
251+
252+
it should "fail when deserializing null input for map if FAIL_ON_NULL_CREATOR_PROPERTIES enabled" in {
253+
val input = """{}"""
254+
val mapper = newBuilder.enable(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES).build()
255+
intercept[com.fasterxml.jackson.databind.exc.MismatchedInputException] {
256+
mapper.readValue(input, classOf[MapHolder[Int, String]])
257+
}
258+
}
243259
}

0 commit comments

Comments
 (0)