-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/test/scala-2.+/tools/jackson/module/scala/deser/AnyValDeserializerTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package tools.jackson.module.scala.deser | ||
|
||
import tools.jackson.module.scala.{DefaultScalaModule, JacksonModule} | ||
|
||
import scala.util.Properties.versionNumberString | ||
|
||
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) | ||
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)) | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/test/scala-2.+/tools/jackson/module/scala/ser/AnyValSerializerTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package tools.jackson.module.scala.ser | ||
|
||
import tools.jackson.module.scala.BaseFixture | ||
|
||
import scala.util.Properties.versionNumberString | ||
|
||
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}""" | ||
if (!versionNumberString.startsWith("2.11")) { | ||
// see https://github.com/FasterXML/jackson-module-scala/pull/675 | ||
mapper.writeValueAsString(BigIntOptionAnyValHolder(Some(value))) shouldBe """{"value":{"underlying":42}}""" | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters