https://kotlinlang.org logo
#getting-started
Title
# getting-started
n

Nikola Milovic

01/11/2022, 1:19 PM
Hello everyone I have a data class
Copy code
import kotlinx.serialization.Serializable

@Serializable
data class MessageModel (val senderId : String, val channelId : String, val id : String, val contents : String, val date : Long)
And when I do this inside my (this is a multiplatform project) web app
Copy code
console.log(message.date::class.simpleName )
The result is
Double
!! What is happening here? It's causing me runtime errors, as I need a long. This MessageModel I receive from my backend and the value of the date is epoch milis, and the value is
1641905913211
this is interpreted as double. But if I don't use the value of
message.date
and instead just directly input
1641905913211
it works, meaning the value isn't the issue, but for some reason when serializing it becomes a double? Not sure where to ask this, is this Multiplatform issue, Kotlin general issue?
Copy code
const val kotlin = "1.6.10"
    const val kotlinxSerialization = "1.3.2"
e

ephemient

01/11/2022, 2:40 PM
n

Nikola Milovic

01/11/2022, 2:45 PM
@ephemient thanks, was looking for the issue But wait, this is about rounding, while I am getting an incorrect type serialized. Is this the same issue?
e

ephemient

01/11/2022, 2:49 PM
yes, long is being rounded into double representation
n

Nikola Milovic

01/11/2022, 2:50 PM
Oh, that's weird. Can't wait for the fix
e

ephemient

01/11/2022, 2:51 PM
also note that Kotlin/JS uses the JS number type so it doesn't really have a distinction between integer and floating types (it tries, but except for Long, it's a compile time thing only)
2 Views