You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
.Expected behavior: Should be able to decode integer/long values containing an exponent.
Environment:
The text was updated successfully, but these errors were encountered: