You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
truncateToInt does not truncate Long number that is greater than Int.MaxValue to Int.MaxValue
Example(in scala repl) Input:
import argonaut.JsonLong
val intMaxPlusOne = JsonLong(2147483648L).truncateToInt
val intMax = JsonLong(2147483647).truncateToInt
val long = JsonLong(100000000000L).truncateToInt
Output:
intMaxPlusOne: Int = -2147483648
intMax: Int = 2147483647
long: Int = 1215752192
Another example with codecs(also in scala repl): Input:
import argonaut.{CodecJson, Json}
import argonaut.Argonaut._
val json = Json(
"long" := 10002100000000L
)
case class DecodedInt(truncatedInt: Int)
implicit def DecodedIntCodec: CodecJson[DecodedInt] =
casecodec1(DecodedInt.apply, DecodedInt.unapply)("long")
val decoded = json.as[DecodedInt].value.get.truncatedInt
Output:
json: argonaut.Json = {"long":10002100000000}
defined class DecodedInt
DecodedIntCodec: argonaut.CodecJson[DecodedInt]
decoded: Int = -878832384
Scala version: 2.12.10 Argonaut version: 6.2.5
The text was updated successfully, but these errors were encountered:
argonaut 6.1.x: def truncateToInt: Int = toDouble.toInt
argonaut 6.2.x: def truncateToInt: Int = toBigDecimal.toInt
I suppose that these changes were made due to the addition of lazy val toDouble in JsonNumber instead JsonDecimal. truncateToInt will work with truncateToDouble instead of toBigDecimal.
truncateToInt does not truncate Long number that is greater than Int.MaxValue to Int.MaxValue
Example(in scala repl)
Input:
Output:
Another example with codecs(also in scala repl):
Input:
Output:
Scala version: 2.12.10
Argonaut version: 6.2.5
The text was updated successfully, but these errors were encountered: