Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add AnyValDeserializerTest #676

Merged
merged 1 commit into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.fasterxml.jackson.module.scala.deser

import com.fasterxml.jackson.module.scala.deser.AnyValDeserializerTest.DoubleAnyValHolder
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)
//mapper.readValue("""{"value":{"underlying":42}}""", classOf[BigIntOptionAnyValHolder]) shouldEqual
//BigIntOptionAnyValHolder(Some(expected))
}
}