Skip to content

Commit

Permalink
add int serialization test
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Sep 15, 2024
1 parent 4a755b4 commit facbdf0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions play-json/jvm/src/test/scala/play/api/libs/json/JsonSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,24 @@ class JsonSpec extends org.specs2.mutable.Specification {
fromJson[JsonNode](jsNum).map(_.toString).must_==(JsSuccess("12.345"))
}

"Serialize JsNumbers with integers correctly" in {
val numStrings = Seq(
"0",
"1",
"-1",
Int.MaxValue.toString,
Int.MinValue.toString,
Long.MaxValue.toString,
Long.MinValue.toString,
(Long.MaxValue + 1).toString,
(Long.MinValue - 1).toString
)
numStrings.map { numString =>
val bigDec = new java.math.BigDecimal(numString)
Json.stringify(JsNumber(bigDec)).must_==(bigDec.toString)
}
}

"Serialize JsNumbers with e notation correctly" in {
val numStrings = Seq(
"1.23456789012345679012345679e999",
Expand Down

0 comments on commit facbdf0

Please sign in to comment.