From 9f9317d305b295bf2bc4313dfefdf47a0503ed84 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 17 Jan 2025 00:12:43 +0100 Subject: [PATCH] try to fix tests due to #698 --- .../tools/jackson/module/scala/deser/CreatorTest.scala | 5 ++++- .../module/scala/deser/DefaultValueDeserializerTest.scala | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/test/scala/tools/jackson/module/scala/deser/CreatorTest.scala b/src/test/scala/tools/jackson/module/scala/deser/CreatorTest.scala index 0c8ed96f..3dd3f0a7 100755 --- a/src/test/scala/tools/jackson/module/scala/deser/CreatorTest.scala +++ b/src/test/scala/tools/jackson/module/scala/deser/CreatorTest.scala @@ -3,7 +3,7 @@ package tools.jackson.module.scala.deser import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonCreator.Mode import tools.jackson.core.`type`.TypeReference -import tools.jackson.databind.{JsonNode, MapperFeature, ObjectMapper} +import tools.jackson.databind.{DeserializationFeature, JsonNode, MapperFeature, ObjectMapper} import tools.jackson.databind.json.JsonMapper import tools.jackson.databind.node.IntNode import tools.jackson.module.scala.introspect.ScalaAnnotationIntrospectorModule @@ -178,6 +178,7 @@ class CreatorTest extends DeserializationFixture { .build() val mapper = initBuilder() .addModule(scalaModule) + .configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false) .build() val deser = mapper.readValue("""{}""", classOf[ConstructorWithDefaultValues]) deser.s shouldEqual null @@ -195,6 +196,7 @@ class CreatorTest extends DeserializationFixture { .build() val mapper = initBuilder() .addModule(scalaModule) + .configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false) .build() val deser = mapper.readValue("""{}""", classOf[ConstructorWithDefaultValues]) deser.s shouldEqual null @@ -208,6 +210,7 @@ class CreatorTest extends DeserializationFixture { it should "ignore default values (when MapperFeature is overridden)" in { _ => val builder = initBuilder() .disable(MapperFeature.APPLY_DEFAULT_VALUES) + .configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false) .addModule(DefaultScalaModule) val mapper = builder.build() val deser = mapper.readValue("""{}""", classOf[ConstructorWithDefaultValues]) diff --git a/src/test/scala/tools/jackson/module/scala/deser/DefaultValueDeserializerTest.scala b/src/test/scala/tools/jackson/module/scala/deser/DefaultValueDeserializerTest.scala index 12e40c26..6c170df1 100644 --- a/src/test/scala/tools/jackson/module/scala/deser/DefaultValueDeserializerTest.scala +++ b/src/test/scala/tools/jackson/module/scala/deser/DefaultValueDeserializerTest.scala @@ -1,5 +1,6 @@ package tools.jackson.module.scala.deser +import tools.jackson.databind.DeserializationFeature import tools.jackson.module.scala.DefaultScalaModule object DefaultValueDeserializerTest { @@ -25,7 +26,11 @@ class DefaultValueDeserializerTest extends DeserializerTest { // 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]) + val mapper = newBuilder + .configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false) + .build() + + val d = mapper.readValue(json, classOf[Defaulted]) d.id shouldEqual 0 d.name shouldEqual "123" }