Hey, I have a timestamp like this `2025-09-02T10:5...
# getting-started
h
Hey, I have a timestamp like this
2025-09-02T10:59:38+02:00
and at one point (envelope) I deserialize it as
Instant
with no problem. At another point (payload) I want to do the same but it doesn't work. I looked at the imports but both import
kotlinx.datetime.Instant
. But one does so from
org.jetbrains.kotlinx:kotlinx-datetime
and the other from
org.jetbrains.kotlinx:kotlinx-datetime-jvm
, with the latter not working. The only dependency I have in both my
common
and
jvmBackend
modules is
org.jetbrains.kotlinx:kotlinx-datetime
so I guess it selects which one to use by itself. What would be the best course of action to remedy this Problem? Edit: Seems like I have to use
Instant.parse()
, before I had the json serializer do it, since most payloads are json and a select few are plain strings, but before I had no problems just using the json parser for that and it allowed me to have a more generic approach for all messages.
k
What do you mean by "it doesn't work"?
h
Hey, my edit overlapped with your comment. I got it working, see the edit above. I don't have the log anymore, but it was something along the lines of "expected t got T at 13, expected - got 2 at 0". Which is weird because for the envelope I am still using the json parser.
For clarification, what I originally tried was:
Copy code
data class MyEnvelope(
  val timestamp: Instant
}

json.deserialize<MyEnvelope>(message)
with
message
being
Copy code
{
  timestamp: "2025-09-02T10:59:38+02:00"
}
Which worked. But
Copy code
json.deserialize<Instant>(message)
with
message
Copy code
2025-09-02T10:59:38+02:00
doesn't work.
k
Which JSON deserializer are you using? Most of them have a problem deserializing
kotlinx.datetime.Instant
from an ISO string, because
Instant
is a inline value class, and so the function sees it as just a
Long
.