amnaredo / test

0 stars 0 forks source link

`ujson.read` parse unexpected Long value when parsing big number literals #257

Open amnaredo opened 2 years ago

amnaredo commented 2 years ago
$ amm
Loading...
Welcome to the Ammonite Repl 1.6.9
(Scala 2.13.0 Java 1.8.0_222)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@ val expected = 1234567890123456789L
expected: Long = 1234567890123456789L

@ val json = ujson.read("""{"a":1234567890123456789}""")
json: ujson.Value.Value = Obj(LinkedHashMap("a" -> Num(1.23456789012345677E18)))

@ json.obj("a").num.toLong == expected
res3: Boolean = false

@ // workaround

@ import upickle.default._
import upickle.default._

@ case class LongValue(a: Long)
defined class LongValue

@ implicit val reader: Reader[LongValue] = macroR
reader: Reader[LongValue] = ammonite.$sess.cmd6$$anon$1@37c49a55

@ upickle.default.read[LongValue]("""{"a":1234567890123456789}""").a == expected
res7: Boolean = true

ID: 278 Original Author: NomadBlacky

amnaredo commented 2 years ago

this is working as intended Original Author: lihaoyi