-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support encoding/decoding non-Long numbers #163
Comments
yeah, we thought about that with @NightEule5, TOML standard (as we understand it) prohibits the usage of INT. "Arbitrary 64-bit signed integers (from −2^63 to 2^63−1) should be accepted and handled losslessly. If an integer cannot be represented losslessly, an error must be thrown." Probably my understanding was wrong 🤦 |
Actually everything will start working if we simply remove this exception. I just wanted to be very straight-forward with spec... 🤣 |
Looks like the change should be a little bit more complicated: we will need to support TomlInteger class and use it during parsing with avoiding of overflow: https://stackoverflow.com/questions/74510016/how-to-understand-if-there-was-an-integer-overflow-during-parsing-of-string-with |
I didn't think it would be that difficult, so maybe I'm missing something :)
This is similar to how Kotlinx Serialization JSON does it. I've made a demo PR |
Currently when I try to decode an integer to a
Int
, I get an error. This is inconvenient, and confusing.Comparison with Kotlinx Serialization
This is confusing because it does not match the behaviour of Kotlinx Serialization JSON. Technically, the JSON spec states that any number can be of any magnitude or precision (so basically KxS should only support
BigDecimal
orBigInteger
), but KxS allows for numbers to be en/decoded with any numeric type -Long
,Short
,Double
,Float
- including unsigned numbers.KxS throws a runtime error when it encounters an invalid number
Work arounds
Custom Serializer
I have tried to work around this with a custom serializer, but I get the same error.
.toInt()
Manually converting on-the-fly with
config.port.toInt()
is possible, but inconvenient, especially if the value is used in a lot of places.Secondary value
I guess it's possible to create a secondary value to expose the actual value...? But this is weird and confusing.
Request
I would like ktoml to coerce numbers to the value in the
@Serializable
class. If an unsuitable value is encountered (for example, it is too large), then ktoml should throw an exception at runtime.Versions
The text was updated successfully, but these errors were encountered: