Permalink
Switch branches/tags
jackson-module-scala-2.9.0 jackson-module-scala-2.9.0.pr3 jackson-module-scala-2.9.0.pr2 jackson-module-scala-2.9.0.pr1 jackson-module-scala-2.8.9 jackson-module-scala-2.8.8 jackson-module-scala-2.8.7 jackson-module-scala-2.8.6 jackson-module-scala-2.8.5 jackson-module-scala-2.8.3 jackson-module-scala-2.8.2 jackson-module-scala-2.8.1 jackson-module-scala-2.8.0.rc2 jackson-module-scala-2.8.0.rc1 jackson-module-scala-2.7.9 jackson-module-scala-2.7.8 jackson-module-scala-2.7.7 jackson-module-scala-2.7.6 jackson-module-scala-2.7.5 jackson-module-scala-2.7.4 jackson-module-scala-2.7.3 jackson-module-scala-2.7.2 jackson-module-scala-2.6.7.1 jackson-module-scala-2.6.7 jackson-module-scala-2.6.6 jackson-module-scala-2.6.5 jackson-module-scala-2.6.4 jackson-module-scala-2.6.3 jackson-module-scala-2.6.2 jackson-module-scala-2.6.1 jackson-module-scala-2.6.0-rc4 jackson-module-scala-2.6.0-rc2 jackson-module-scala-2.6.0-1 jackson-module-scala-2.5.3 jackson-module-scala-2.5.2 jackson-module-scala-2.5.1 jackson-module-scala-2.5.0 jackson-module-scala-2.4.5 jackson-module-scala-2.4.5-1 jackson-module-scala-2.4.4 jackson-module-scala-2.4.3 jackson-module-scala-2.4.2 jackson-module-scala-2.4.1 jackson-module-scala-2.4.0 jackson-module-scala-2.4.0-rc2 jackson-module-scala-2.4.0-rc1 jackson-module-scala-2.3.5 jackson-module-scala-2.3.4 jackson-module-scala-2.3.3 jackson-module-scala-2.3.2 jackson-module-scala-2.3.1 jackson-module-scala-2.3.0 jackson-module-scala-2.3.0-rc1 jackson-module-scala-2.2.3 jackson-module-scala-2.2.2 jackson-module-scala-2.2.1 jackson-module-scala-2.2.0 jackson-module-scala-2.2.0-rc1 jackson-module-scala-2.1.5 jackson-module-scala-2.1.4 jackson-module-scala-2.1.3 jackson-module-scala-2.1.2 jackson-module-scala-2.1.1 jackson-module-scala-2.1.0 jackson-module-scala-2.0.4 jackson-module-scala-2.0.3 jackson-module-scala-2.0.2 jackson-module-scala-2.0.0 jackson-module-scala-2.0.0-RC2 jackson-module-scala-1.9.3 jackson-module-scala-1.9.2 jackson-module-scala-1.9.1 jackson-module-scala-1.9.0 jackson-module-scala-0.5.0 fork_scala-2.10.0-M7 fork_before_scala-2.10.0_changes
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
61 lines (47 sloc) 2.09 KB
package com.fasterxml.jackson.module.scala.deser
import com.fasterxml.jackson.databind.JsonMappingException
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
object PrimitiveContainerTest {
case class OptionInt(value: Option[Int])
case class AnnotatedOptionInt(@JsonDeserialize(contentAs = classOf[java.lang.Integer]) value: Option[Int])
case class OptionLong(value: Option[Long])
case class AnnotatedOptionLong(@JsonDeserialize(contentAs = classOf[java.lang.Long]) value: Option[Long])
case class AnnotatedHashKeyLong(@JsonDeserialize(keyAs = classOf[java.lang.Long]) value: Map[Long, String])
case class AnnotatedHashValueLong(@JsonDeserialize(contentAs = classOf[java.lang.Long]) value: Map[String, Long])
}
@RunWith(classOf[JUnitRunner])
class PrimitiveContainerTest extends DeserializationFixture
{
import PrimitiveContainerTest._
behavior of "Primitive Containers"
it should "support deserializing primitives" in { f =>
val value = f.readValue[OptionInt]("""{"value":1}""")
value.value shouldBe Some(1)
}
it should "support primitive conversions in" in { f =>
val value = f.readValue[AnnotatedOptionInt]("""{"value":"1"}""")
value.value shouldBe Some(1)
}
it should "support type widening" in { f =>
val value = f.readValue[AnnotatedOptionLong]("""{"value":1}""")
value.value.get shouldBe 1L
}
it should "enforce type constraints" in { f =>
val thrown = intercept[JsonMappingException] {
f.readValue[AnnotatedOptionInt]("""{"value":9223372036854775807}""").value.get
}
thrown.getMessage should startWith ("Numeric value (9223372036854775807) out of range")
}
it should "support map keys" in { f =>
val value = f.readValue[AnnotatedHashKeyLong]("""{"value":{"1":"one"}}""")
value.value should contain key 1L
value.value(1L) shouldBe "one"
}
it should "support map values" in { f =>
val value = f.readValue[AnnotatedHashValueLong]("""{"value":{"key": "1"}}""")
value.value should contain key "key"
value.value("key") shouldBe 1L
}
}