kotlinx.serialization icon indicating copy to clipboard operation
kotlinx.serialization copied to clipboard

Decoding a JSON integer value containing an exponent and a decimal point

Open illarionov opened this issue 8 months ago • 1 comments

Currently, numeric JSON values ​​containing a decimal point cannot be decoded as integer types. An example of such values: 1.0, 1.0E1, -1.5E3, 0.5e2.

Decoding it as long fails with an error:

println(Json.decodeFromString<Int>("1.0e1"))
kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 0: Unexpected symbol '.' in numeric literal at path: $

It would be beneficial if these values could be decoded. Alternatively, it should be documented that such form is not supported.

illarionov avatar Apr 04 '25 22:04 illarionov

Note: input like 1e1 is allowed for Ints

sandwwraith avatar Apr 07 '25 13:04 sandwwraith