Skip to content

Commit 797c5e9

Browse files
committed
separate test case out from Option tests
1 parent cb8fc12 commit 797c5e9

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.fasterxml.jackson.module.scala.deser
2+
3+
import com.fasterxml.jackson.module.scala.DefaultScalaModule
4+
5+
object DefaultValueDeserializerTest {
6+
7+
case class Defaulted(id: Int, name: String = "") {
8+
def this() = this(1)
9+
}
10+
11+
}
12+
13+
class DefaultValueDeserializerTest extends DeserializerTest {
14+
import DefaultValueDeserializerTest._
15+
lazy val module: DefaultScalaModule.type = DefaultScalaModule
16+
17+
"An ObjectMapper with DefaultScalaModule" should "deserialize defaulted parameters correctly" in {
18+
val json = newMapper.writeValueAsString(Defaulted(id = 1))
19+
json shouldBe """{"id":1,"name":""}"""
20+
val d = deserialize(json, classOf[Defaulted])
21+
d.name shouldEqual ""
22+
}
23+
24+
it should "deserialize defaulted parameters correctly (ignores 2nd constructor)" in {
25+
// this may not be ideal but it is the existing behaviour so we will probably need
26+
// a config or annotation to get the test to use the 2nd constructor
27+
val json = """{"name":"123"}"""
28+
val d = deserialize(json, classOf[Defaulted])
29+
d.id shouldEqual 0
30+
d.name shouldEqual "123"
31+
}
32+
}

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ object OptionDeserializerTest {
2929
def base_=(base:Option[Base]): Unit = { _base = base }
3030
}
3131

32-
case class Defaulted(id: Int, name: String = "") {
33-
def this() = this(1,"")
34-
}
35-
3632
case class Foo(bar: String)
3733
case class TWrapper[T](t: T)
3834

@@ -86,13 +82,6 @@ class OptionDeserializerTest extends DeserializerTest {
8682
deserialize("""{"base":null}""", classOf[BaseHolder]) should be(BaseHolder(None))
8783
}
8884

89-
it should "deserialize defaulted parameters correctly (without defaults)" in {
90-
val json = newMapper.writeValueAsString(Defaulted(id = 1))
91-
json shouldBe """{"id":1,"name":""}"""
92-
val d = deserialize(json, classOf[Defaulted])
93-
d.name should not be null
94-
}
95-
9685
it should "deserialize a type param wrapped option" in {
9786
val json: String = """{"t": {"bar": "baz"}}"""
9887
val result = deserialize(json, new TypeReference[TWrapper[Option[Foo]]] {})

0 commit comments

Comments
 (0)