Skip to content

How to serialize BigInteger and BigDouble? #1051

@MMairinger

Description

@MMairinger

Currently I'm in the need of serializing numbers with many decimal digits (30+ decimal digits to be more precise). To deserialzie a JSON file with this many decimal points I used Java's BigIntegers and BigDecimal types which works fine. The problem that arises is when I want to serialize that value. It will be serialized as an Integer or Double respectively which cuts and rounds the actual value.

One example value is this, received in a JSON file.
0.083532162010669708251953125000
After deserializing I will have exactly a value of that above as a JsonLiteral. But when I serialize this value I will get a result of:
0.08353216201066971
Which is not my desired result.
A snippet from my unit tests showing the differences between expected and actual:
image

My questions are now how should I serialized BigIntegers and BigDoubles and will there be support for this kind of data types in the future?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions