ionspin / kotlin-multiplatform-bignum

A Kotlin multiplatform library for arbitrary precision arithmetics
Apache License 2.0
362 stars 41 forks source link

Support Number jsons #219

Closed BraisGabin closed 2 years ago

BraisGabin commented 2 years ago

humanReadableSerializerModule should allow to parase things like:

"price": {
    "amount": 12.34,
    "currency": "€"
}

But right now it forces to use "12.34". We shouldn't lose any precision by using a number of json. We shouldn't lose any precision by using 12.34.

From backend I'm receiving that and with Moshi I hadn't any problem. On moshi I read 12.34 as a String (even it is a number in the json) and I parse it to BigDecimal.

ionspin commented 2 years ago

Hi @BraisGabin as far as I am aware it's not possible to encode it that way without precision loss, and the limitation is on the KotlinX serialization side. You can see the issue regarding this here https://github.com/Kotlin/kotlinx.serialization/issues/1051 Specifically this comment https://github.com/Kotlin/kotlinx.serialization/issues/1051#issuecomment-812130020

I'm closing this issue as there is nothing to on our side at the moment.

BraisGabin commented 2 years ago

Thanks for the fast replay! It seems that they are tracking this "feature" here: https://github.com/Kotlin/kotlinx.serialization/issues/1405

ionspin commented 2 years ago

Good to know, thanks!

aSemy commented 1 year ago

Hi, just a quick heads up that I'm working on supporting BigDecimal/BigInteger in this PR https://github.com/Kotlin/kotlinx.serialization/pull/2041.

I'm a contributor to KxS, not a maintainer, so I can't give any timescale, but hopefully it's soon 🤞

I'd like to be able to help implement support in in this library when it's available! As a preview, you can see the test I wrote for BigDecimal - I expect a serializer for BigNum will be similar https://github.com/Kotlin/kotlinx.serialization/pull/2041/files#diff-46d155dec31ebfaed1e644398258f05f18332f9af8454854f863c0100019eb41