Skip to content

Commit

Permalink
separate test case out from Option tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Aug 1, 2024
1 parent cb8fc12 commit 797c5e9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.fasterxml.jackson.module.scala.deser

import com.fasterxml.jackson.module.scala.DefaultScalaModule

object DefaultValueDeserializerTest {

case class Defaulted(id: Int, name: String = "") {
def this() = this(1)
}

}

class DefaultValueDeserializerTest extends DeserializerTest {
import DefaultValueDeserializerTest._
lazy val module: DefaultScalaModule.type = DefaultScalaModule

"An ObjectMapper with DefaultScalaModule" should "deserialize defaulted parameters correctly" in {
val json = newMapper.writeValueAsString(Defaulted(id = 1))
json shouldBe """{"id":1,"name":""}"""
val d = deserialize(json, classOf[Defaulted])
d.name shouldEqual ""
}

it should "deserialize defaulted parameters correctly (ignores 2nd constructor)" in {
// this may not be ideal but it is the existing behaviour so we will probably need
// a config or annotation to get the test to use the 2nd constructor
val json = """{"name":"123"}"""
val d = deserialize(json, classOf[Defaulted])
d.id shouldEqual 0
d.name shouldEqual "123"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ object OptionDeserializerTest {
def base_=(base:Option[Base]): Unit = { _base = base }
}

case class Defaulted(id: Int, name: String = "") {
def this() = this(1,"")
}

case class Foo(bar: String)
case class TWrapper[T](t: T)

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

it should "deserialize defaulted parameters correctly (without defaults)" in {
val json = newMapper.writeValueAsString(Defaulted(id = 1))
json shouldBe """{"id":1,"name":""}"""
val d = deserialize(json, classOf[Defaulted])
d.name should not be null
}

it should "deserialize a type param wrapped option" in {
val json: String = """{"t": {"bar": "baz"}}"""
val result = deserialize(json, new TypeReference[TWrapper[Option[Foo]]] {})
Expand Down

0 comments on commit 797c5e9

Please sign in to comment.