Skip to content

fix issue with FAIL_ON_NULL_CREATOR_PROPERTIES for collections #734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ abstract class GenericFactoryDeserializerResolver[CC[_], CF[X[_]]](config: Scala
bw.builder.result().asInstanceOf[Object]
}

override def getNullValue(ctxt: DeserializationContext): Object = getEmptyValue(ctxt)
override def getNullValue(ctxt: DeserializationContext): Object = {
if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES))
super.getNullValue(ctxt)
else
getEmptyValue(ctxt)
}

private def newBuilderWrapper(ctxt: DeserializationContext): BuilderWrapper[AnyRef] = {
containerDeserializer.getValueInstantiator.createUsingDefault(ctxt).asInstanceOf[BuilderWrapper[AnyRef]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ abstract class GenericMapFactoryDeserializerResolver[CC[K, V], CF[X[_, _]]](conf
bw.builder.result().asInstanceOf[Object]
}

override def getNullValue(ctxt: DeserializationContext): Object = getEmptyValue(ctxt)
override def getNullValue(ctxt: DeserializationContext): Object = {
if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES))
super.getNullValue(ctxt)
else
getEmptyValue(ctxt)
}

private def newBuilderWrapper(ctxt: DeserializationContext): BuilderWrapper[AnyRef, AnyRef] = {
containerDeserializer.getValueInstantiator.createUsingDefault(ctxt).asInstanceOf[BuilderWrapper[AnyRef, AnyRef]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ class CaseClassDeserializerTest extends DeserializerTest {
result.list shouldBe List.empty
}

it should "fail when deserializing null input for list if FAIL_ON_NULL_CREATOR_PROPERTIES enabled" in {
val input = """{}"""
val mapper = newBuilder.enable(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES).build()
intercept[tools.jackson.databind.exc.MismatchedInputException] {
mapper.readValue(input, classOf[ListHolder[String]])
}
}

it should "support deserializing null input for list as empty list (JsonSetter annotation)" in {
val input = """{}"""
val result = deserialize(input, classOf[AnnotatedListHolder[String]])
Expand Down Expand Up @@ -240,4 +248,12 @@ class CaseClassDeserializerTest extends DeserializerTest {
val result = deserialize(input, classOf[AnnotatedMapHolder[Int, String]])
result.map shouldBe Map.empty
}

it should "fail when deserializing null input for map if FAIL_ON_NULL_CREATOR_PROPERTIES enabled" in {
val input = """{}"""
val mapper = newBuilder.enable(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES).build()
intercept[tools.jackson.databind.exc.MismatchedInputException] {
mapper.readValue(input, classOf[MapHolder[Int, String]])
}
}
}