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 b7fed5b commit e701b21
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ package deser

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.databind.{JsonMappingException, ObjectMapper, ObjectReader, PropertyNamingStrategy}
import com.fasterxml.jackson.databind.{DeserializationFeature, JsonMappingException, ObjectMapper, ObjectReader, PropertyNamingStrategy}
import com.fasterxml.jackson.module.scala.ser.{ClassWithOnlyUnitField, ClassWithUnitField}

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 @@ -163,6 +165,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[com.fasterxml.jackson.databind.exc.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 e701b21

Please sign in to comment.