Hi guys! :slightly_smiling_face: There is a way t...
# announcements
m
Hi guys! 🙂 There is a way to serialize with
@Serializable
a
java.util.Date
with this format
2018-11-14T13:25:30Z
? I´m using Ktor and
kotlinx.serialization
s
Use a custom serializer as described here: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serializers.md#serializing-3rd-party-classes But instead of converting the date to a long & vice versa, you convert it to the ISO 8601 string and back.
p
If you don't specifically need a
java.util.Date
(which are soft-deprecated anyways):
Oops, that's also got an extension:
Copy code
fun String.toInstantOrNull(): Instant? = runCatching { Instant.parse(this) }.getOrNull()
m
👍