2

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.

  • 3
    Importing the `kotlinx-datetime` library is not enough; you have to use the types from that library, instead of `java.time`, as the `kotlinx-datetime` types are annotated with the appropriate `@Serializable` annotations. If you wish to continue using the `java.time` types directly, then you'll need to create your own serializers. See [this related Q&A](https://stackoverflow.com/q/71629874/6395627). It none of this helps solve your problem then please provide a [mre]. – Slaw Mar 28 '23 at 07:59

0 Answers0