com-lihaoyi / upickle

uPickle: a simple, fast, dependency-free JSON & Binary (MessagePack) serialization library for Scala
https://com-lihaoyi.github.io/upickle
MIT License
707 stars 158 forks source link

ujson deseralizer will parse big integer value wrong #566

Closed qzwsq closed 3 months ago

qzwsq commented 3 months ago

Dependencies

libraryDependencies += "com.lihaoyi" %% "os-lib" % "0.9.3", libraryDependencies += "com.lihaoyi" %% "upickle" % "3.2.0"

Test Code

// test.scala
 @main def test(): Unit =
  println(os.read(os.pwd/"data"/"test.json"))
  println(ujson.read(os.read(os.pwd/"data"/"test.json")))

Test Data

{"id": 6821264719157920773}

Result

Multiple main classes detected. Select one to run:
 [1] hello
 [2] test

Enter number: 2
[info] running test 
{"id": 6821264719157920773}
{"id":6821264719157920768}
[success] Total time: 7 s, completed 2024年3月21日 下午8:59:00

Environment

Scala code runner version 3.4.0
lihaoyi commented 3 months ago

This is expected. ujson follows the Javascript data model, including 64-bit floating point numbers only. If you want to parse Longs or other data types, you want upickle.default.read[Map[String, Long]](...)