Is it possible to set serialization configuration ...
# kvision
t
Is it possible to set serialization configuration for whole project? We have a custom serialization configuration (using open polymorphic class structure) and we need same config in Rest client and Form. (unfortunately we are still on version 4, but I am wondering whether the latest version support something like this)
r
No such feature at the moment. You can fill a feature request, I think it can be done.
t
Thanks, I'll add issue.
r
Hi, could you please specify what configuration do you need? Is it just about cusom serializers?
Or perhaps some other options as well?
t
my current config:
Copy code
val instance = Json {
        ignoreUnknownKeys = true
        isLenient = true
        encodeDefaults = true
        serializersModule = SerializersModule {
            contextual(Date::class, DateSerializer)
            polymorphic(Entity::class) {
                subclass(Application::class)
                subclass(Asset::class)
                subclass(DialogueMixin::class)
                subclass(File::class)
                subclass(Voice::class)
            }
        }
        classDiscriminator = "__class"
    }
So I need other options as well
r
I'm asking because there are options which should not be changed in specific applications (e.g. inside Form)
t
Which one?
r
encodeDefaults = true
it will not work correctly if someone makes it false
t
I see.
r
But I'll probably just leave it to the user
t
You can create own instance of Json overriding it
something like:
Copy code
val customMapper:Json = Json {...}

val formMapper = Json(from = customMapper) {
    encodeDefaults = true
}
r
Nice
I have a problem that I didn't think about before.
I've made
kvision-rest
module independent from KVision itself.
And now I can't make shared configuration.
it was not specifically announced so probably no one is using RestClient without KVision 😉 I'll just restore the dependency and we will see if there will be complaints ...