Charann
03/10/2025, 5:26 AMfun 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?Ahmed
03/10/2025, 3:06 PM1.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? 😸