com-lihaoyi / upickle

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

Reading json with more than 16 digits is converted to scientific notation #520

Closed mokexinxin closed 1 year ago

mokexinxin commented 1 year ago

When I use it, the parameters passed in are: {'a':11111111111111111111111111111111}

The result I got is: {"a":1.1111111111111112E31}

I want to get the number itself, not the scientific notation. Is there a solution?

lihaoyi commented 1 year ago

Should be fixed by https://github.com/com-lihaoyi/upickle/pull/521, which allows you to parse the number as a String if you want to preserve the full literal contents. This gives you an option if the JVM numeric types Byte/Short/Int/Long/Float/Double do not have the precision you need

          upickle.default.read[Map[String, String]]("""{"a":11111111111111111111111111111111}""") ==
          Map("a" -> "11111111111111111111111111111111")