Skip to content
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

Decoding an integer value containing an exponent #2078

Closed
hemantgokhale opened this issue Oct 25, 2022 · 0 comments
Closed

Decoding an integer value containing an exponent #2078

hemantgokhale opened this issue Oct 25, 2022 · 0 comments

Comments

@hemantgokhale
Copy link

I recently came across a situation where a JSON minifier minified an integer value with 3 or more trailing zeros using an exponent. E.g. 1000 minified to 1e3. It appears that the JSON spec allows this, but kotlinx.serialization currently doesn't handle it.

As a side note, I have verified that Swift’s implementation of JSONSerialization (MacOS 12.6, Swift 5.7) handles this situation correctly i.e. decodes 1e3 to 1000.

Example code:
The first statement in main() works as expected. The second statement throws kotlinx.serialization.json.internal.JsonDecodingException.

import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json

@Serializable
data class SomeData(val count: Int)

fun main() {
    println(Json.decodeFromString<SomeData>("""{ "count": 1000 }"""))
    println(Json.decodeFromString<SomeData>("""{ "count": 1e3 }"""))
}

Expected behavior: Should be able to decode integer/long values containing an exponent.

Environment:

  • Kotlin version: 1.7.20
  • Library version: 1.4.1
  • Kotlin platforms: JVM (I didn’t check the behavior on other platforms)
  • Gradle version: 7.4.2
  • IDE version: IntellijIDEA 2022.2.3
  • MacOS 12.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants