How would I go about serializing LocalDateTime
using kotlinx serializer
I've read that I would need to include implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
in my dependencies, which I did, but I'm still getting this error:
Serializer has not been found for type 'LocalDateTime'. To use context serializer as fallback, explicitly annotate type or property with @Contextual
Is there something else I should also imported in the same script?
Thanks for your time.
kotlinx-datetime
library is not enough; you have to use the types from that library, instead ofjava.time
, as thekotlinx-datetime
types are annotated with the appropriate@Serializable
annotations. If you wish to continue using thejava.time
types directly, then you'll need to create your own serializers. See this related Q&A. It none of this helps solve your problem then please provide a minimal reproducible example. – Brockwell