kotlinx.serialization
kotlinx.serialization copied to clipboard
Decoding a JSON integer value containing an exponent and a decimal point
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.
Note: input like 1e1 is allowed for Ints