In the below case, I expected the serializer to de...
# serialization
c
In the below case, I expected the serializer to de-code the scientific notation and consider it is as a "long"
Copy code
fun testSerializer(){
    val str = """{"doubleVal":1.725255546765E12}"""
    val json = Json {
        isLenient = true
    }
    val obj = json.decodeFromString<DoubleVal>(str)
    println(obj)
}
@Serializable
class DoubleVal(val doubleVal: Long)
But I got an error "Unexpected JSON token at offset 13: Unexpected symbol '.' in numeric literal at path: $.doubleVal" I tried using flags like "isLenient" but of no use. Am I missing any flags?
a
1.725255546765E12
is either float or double according to IEEE specs. So you cannot parse it into
Long
type with default behaviour. You would want a custom kserialiser to achieve this. You have already named it as
doubleVal
. Why not change the type to
Double
as well? 😸