Hi all. I'm learning kotlinx.serialization and I h...
# serialization
i
Hi all. I'm learning kotlinx.serialization and I have a question Let's say I have a data class like this:
Copy code
data class Data(val a: String, val b: String)
Now, I know I could add @Serializable and have everything generated for me. But what if I can't annotate this class, it is not in my code? Do i need to write the serialization manually or is there a way to automatically generate KSerializer for it?
t
i
Thanks, exactly what I was looking for, don't know how I missed this
So now I have another issue and I get a codegen error. The data class I am trying to add serializer for has a val of type LocalDateTime, which is not serialized by default by kotlinx.serialization. I have written KSerializer for that class. Do you know if I can somehow tell @Serializer to use that KSerializer for LocalDateTime? Something like @ContextualSerialization (I doesn't allow me to use that over this object, which I expected, I don't know if there is any other way to set it)
nevermind, I got it, it's much simpler than it seems 😄 i used
Copy code
file:UseSerializers
Thanks a lot for the help
g
this, or you can register a serializer for your type in serial module of your Json configuration. (Beware that neither of this will work with Retrofit at the moment.)