Skip to content

Commit ca80810

Browse files
committed
add deser tests for empty lists
1 parent 298f51a commit ca80810

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

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

3-
import com.fasterxml.jackson.annotation.JsonProperty
3+
import com.fasterxml.jackson.annotation.{JsonProperty, JsonSetter, Nulls}
44
import tools.jackson.databind.annotation.JsonDeserialize
55
import tools.jackson.databind.exc.MismatchedInputException
66
import tools.jackson.databind.json.JsonMapper
@@ -69,6 +69,9 @@ object CaseClassDeserializerTest {
6969
class NestedB(id: Int) {
7070
def x = id
7171
}
72+
73+
case class ListHolder[T](list: List[T])
74+
case class AnnotatedListHolder[T](@JsonSetter(nulls = Nulls.AS_EMPTY)list: List[T])
7275
}
7376

7477
class CaseClassDeserializerTest extends DeserializerTest {
@@ -195,4 +198,16 @@ class CaseClassDeserializerTest extends DeserializerTest {
195198
val result = deserialize(input, classOf[ClassWithOnlyUnitField])
196199
result shouldEqual ClassWithOnlyUnitField(())
197200
}
201+
202+
it should "support deserializing null input for list as empty list" ignore {
203+
val input = """{}"""
204+
val result = deserialize(input, classOf[ListHolder[String]])
205+
result.list shouldBe null // ideally should be empty list, Scala users expect no nulls
206+
}
207+
208+
it should "support deserializing null input for list as empty list (JsonSetter annotation)" in {
209+
val input = """{}"""
210+
val result = deserialize(input, classOf[AnnotatedListHolder[String]])
211+
result.list shouldBe List.empty
212+
}
198213
}

0 commit comments

Comments
 (0)