diff --git a/src/test/scala/com/fasterxml/jackson/module/scala/deser/AnyValDeserializerTest.scala b/src/test/scala-2.+/com/fasterxml/jackson/module/scala/deser/AnyValDeserializerTest.scala similarity index 94% rename from src/test/scala/com/fasterxml/jackson/module/scala/deser/AnyValDeserializerTest.scala rename to src/test/scala-2.+/com/fasterxml/jackson/module/scala/deser/AnyValDeserializerTest.scala index f057c3353..7edd65410 100644 --- a/src/test/scala/com/fasterxml/jackson/module/scala/deser/AnyValDeserializerTest.scala +++ b/src/test/scala-2.+/com/fasterxml/jackson/module/scala/deser/AnyValDeserializerTest.scala @@ -32,7 +32,7 @@ class AnyValDeserializerTest extends DeserializerTest { val expected = BigIntAnyVal(42) mapper.readValue("""{"underlying":42}""", classOf[BigIntAnyVal]) shouldEqual expected mapper.readValue("""{"value":42}""", classOf[BigIntAnyValHolder]) shouldEqual BigIntAnyValHolder(expected) - if (!versionNumberString.startsWith("2.11") && !versionNumberString.startsWith("3")) { + if (!versionNumberString.startsWith("2.11")) { // see https://github.com/FasterXML/jackson-module-scala/pull/675 mapper.readValue("""{"value":{"underlying":42}}""", classOf[BigIntOptionAnyValHolder]) shouldEqual BigIntOptionAnyValHolder(Some(expected)) diff --git a/src/test/scala/com/fasterxml/jackson/module/scala/ser/AnyValSerializerTest.scala b/src/test/scala-2.+/com/fasterxml/jackson/module/scala/ser/AnyValSerializerTest.scala similarity index 93% rename from src/test/scala/com/fasterxml/jackson/module/scala/ser/AnyValSerializerTest.scala rename to src/test/scala-2.+/com/fasterxml/jackson/module/scala/ser/AnyValSerializerTest.scala index 4c360dbe7..2c6aaedd1 100644 --- a/src/test/scala/com/fasterxml/jackson/module/scala/ser/AnyValSerializerTest.scala +++ b/src/test/scala-2.+/com/fasterxml/jackson/module/scala/ser/AnyValSerializerTest.scala @@ -29,7 +29,7 @@ class AnyValSerializerTest extends BaseFixture { val value = BigIntAnyVal(42) mapper.writeValueAsString(value) shouldBe """{"underlying":42}""" mapper.writeValueAsString(BigIntAnyValHolder(value)) shouldBe """{"value":42}""" - if (!versionNumberString.startsWith("2.11") && !versionNumberString.startsWith("3")) { + if (!versionNumberString.startsWith("2.11")) { // see https://github.com/FasterXML/jackson-module-scala/pull/675 mapper.writeValueAsString(BigIntOptionAnyValHolder(Some(value))) shouldBe """{"value":{"underlying":42}}""" } diff --git a/src/test/scala-3/com/fasterxml/jackson/module/scala/deser/AnyValDeserializerTest.scala b/src/test/scala-3/com/fasterxml/jackson/module/scala/deser/AnyValDeserializerTest.scala new file mode 100644 index 000000000..5ac335df4 --- /dev/null +++ b/src/test/scala-3/com/fasterxml/jackson/module/scala/deser/AnyValDeserializerTest.scala @@ -0,0 +1,37 @@ +package com.fasterxml.jackson.module.scala.deser + +import com.fasterxml.jackson.module.scala.{DefaultScalaModule, JacksonModule} + +object AnyValDeserializerTest { + case class DoubleAnyVal(underlying: Double) extends AnyVal + case class DoubleAnyValHolder(value: DoubleAnyVal) + + case class BigIntAnyVal(underlying: BigInt) extends AnyVal + case class BigIntAnyValHolder(value: BigIntAnyVal) + case class BigIntOptionAnyValHolder(value: Option[BigIntAnyVal]) +} + +class AnyValDeserializerTest extends DeserializerTest { + import AnyValDeserializerTest._ + + lazy val module: JacksonModule = DefaultScalaModule + + behavior of "AnyVal" + + it should "deserialize an Double AnyVal" in { + val mapper = newMapper + val expected = DoubleAnyVal(42) + mapper.readValue("""{"underlying":42.0}""", classOf[DoubleAnyVal]) shouldEqual expected + mapper.readValue("""{"value":42.0}""", classOf[DoubleAnyValHolder]) shouldEqual DoubleAnyValHolder(expected) + } + + it should "deserialize an BigInt AnyVal" in { + val mapper = newMapper + val expected = BigIntAnyVal(42) + mapper.readValue("""{"underlying":42}""", classOf[BigIntAnyVal]) shouldEqual expected + mapper.readValue("""{"value":42}""", classOf[BigIntAnyValHolder]) shouldEqual BigIntAnyValHolder(expected) + // see https://github.com/FasterXML/jackson-module-scala/pull/675 + // mapper.readValue("""{"value":{"underlying":42}}""", classOf[BigIntOptionAnyValHolder]) shouldEqual + // BigIntOptionAnyValHolder(Some(expected)) + } +} diff --git a/src/test/scala-3/com/fasterxml/jackson/module/scala/ser/AnyValSerializerTest.scala b/src/test/scala-3/com/fasterxml/jackson/module/scala/ser/AnyValSerializerTest.scala new file mode 100644 index 000000000..f12ec159f --- /dev/null +++ b/src/test/scala-3/com/fasterxml/jackson/module/scala/ser/AnyValSerializerTest.scala @@ -0,0 +1,34 @@ +package com.fasterxml.jackson.module.scala.ser + +import com.fasterxml.jackson.module.scala.BaseFixture + +object AnyValSerializerTest { + case class DoubleAnyVal(underlying: Double) extends AnyVal + case class DoubleAnyValHolder(value: DoubleAnyVal) + + case class BigIntAnyVal(underlying: BigInt) extends AnyVal + case class BigIntAnyValHolder(value: BigIntAnyVal) + case class BigIntOptionAnyValHolder(value: Option[BigIntAnyVal]) +} + +//see AnyVal2SerializerTest for cases that only work with Scala2 and Scala3.3 but not earlier versions of Scala3 +class AnyValSerializerTest extends BaseFixture { + import AnyValSerializerTest._ + + behavior of "AnyVal" + + it should "serialize an Double AnyVal" in { mapper => + val value = DoubleAnyVal(42) + mapper.writeValueAsString(value) shouldBe """{"underlying":42.0}""" + mapper.writeValueAsString(DoubleAnyValHolder(value)) shouldBe """{"value":42.0}""" + } + + it should "serialize an BigInt AnyVal" in { mapper => + val value = BigIntAnyVal(42) + mapper.writeValueAsString(value) shouldBe """{"underlying":42}""" + mapper.writeValueAsString(BigIntAnyValHolder(value)) shouldBe """{"value":42}""" + // see https://github.com/FasterXML/jackson-module-scala/pull/675 + // mapper.writeValueAsString(BigIntOptionAnyValHolder(Some(value))) shouldBe """{"value":{"underlying":42}}""" + } + +}