How can I register serializers for my custom Json ...
# serialization
s
How can I register serializers for my custom Json object? I prefer not to specify serialisers all the time when calling
encodeToString
I have this custom serializer
Copy code
object LocalDateTimeSerializer : KSerializer<LocalDateTime>
and I want to register it to
Copy code
val jsonFormatter = Json {
    ignoreUnknownKeys = true
}
So that I can call,
jsonFormatter.encodeToString(LocaleDateTime.now())
e
Copy code
Json {
    serializersModule = SerializersModule {
        contextual(LocalDateTime::class, LocalDateTimeSerializer)
    }
}
s
Thanks. Is it possible to set my jsonFormatter as the default json, so that I don't have to add annoations on the classes?
e
no
🙏 1