Skip to content

Commit

Permalink
add tests for #203
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Nov 3, 2022
1 parent 1c83522 commit cc32ffb
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package tools.jackson.module.scala.deser

import com.fasterxml.jackson.annotation.JsonProperty
import tools.jackson.databind.annotation.JsonDeserialize
import tools.jackson.databind.exc.MismatchedInputException
import tools.jackson.databind.json.JsonMapper
import tools.jackson.databind.{DatabindException, ObjectMapper, ObjectReader, PropertyNamingStrategies}
import tools.jackson.databind.{DatabindException, DeserializationFeature, ObjectMapper, ObjectReader, PropertyNamingStrategies}
import tools.jackson.module.scala.DefaultScalaModule
import tools.jackson.module.scala.ser.{ClassWithOnlyUnitField, ClassWithUnitField}

Expand All @@ -12,6 +13,8 @@ import java.time.LocalDateTime
object CaseClassDeserializerTest {
class Bean(var prop: String)

case class Time(hour: String, minute: String)

case class ConstructorTestCaseClass(intValue: Int, stringValue: String)

case class PropertiesTestCaseClass() {
Expand Down Expand Up @@ -164,6 +167,22 @@ class CaseClassDeserializerTest extends DeserializerTest {
result.value should equal (Array[Byte](1,2,3))
}

it should "support deserialization with missing field" in {
val input = """{"hour": "12345"}"""
val result = deserialize(input, classOf[Time])
// https://github.com/FasterXML/jackson-module-scala/issues/203
// this result is not popular with users it has been the behaviour for quite some time
result shouldEqual Time("12345", null)
}

it should "fail deserialization with missing field (DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES)" in {
val mapper = newBuilder.enable(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES).build()
val input = """{"hour": "12345"}"""
intercept[MismatchedInputException] {
mapper.readValue(input, classOf[Time])
}
}

it should "support ClassWithUnitField" in {
val input = """{"intField":2}"""
val result = deserialize(input, classOf[ClassWithUnitField])
Expand Down

0 comments on commit cc32ffb

Please sign in to comment.