Stylianos Gakis
07/12/2022, 1:01 PMAction
with normal subclass class SomeAction : Action
and another interface subclass of type interface ServerAction : Action
which itself has implementations like class SpecificServerAction : ServerAction
.
I’ve been trying to think of how I need to setup my SerializersModule to make all of this work.
From what I understand since my interface is not sealed, I need to do something like this
polymorphic(Action::class) {
subclass(ServerAction::class, //??)
subclass(NavigationPushAction::class, NavigationPushAction.serializer())
subclass(NavigationPopAction::class, NavigationPopAction.serializer())
subclass(VoidAction::class, VoidAction.serializer())
}
but how do I do this for the ServerAction? Optimally I’d like to be able to define my ServerAction hierarchy the same way by providing all the subclasses, but I don’t see a way that the dsl allows me to do this?
I could probably do this by creating my own object ServerActionSerializer : KSerializer<ServerAction> {
and implementing it, but I’d rather not if possible? I like this subclass approach which can take care of it for me.
Am I missing something, any ideas maybe? Some part of the api I can be using that I am not?Emil Kantis
07/12/2022, 1:38 PMpolymorphic(Action::class, SpecificServerAction::class, SpecificServerAction.serializer())
Stylianos Gakis
07/12/2022, 2:28 PMpolymorphic
calls if I have many implementations of ServerAction
(which I do)
Something like this:
polymorphic(Action::class) {
subclass(NavigationPushAction::class, NavigationPushAction.serializer())
subclass(NavigationPopAction::class, NavigationPopAction.serializer())
subclass(VoidAction::class, VoidAction.serializer())
}
polymorphic(Action::class, SpecificServerAction::class, SpecificServerAction.serializer())
polymorphic(Action::class, Specific2ServerAction::class, Specific2ServerAction.serializer())
polymorphic(Action::class, Specific3ServerAction::class, Specific3ServerAction.serializer())
... and so on
ServerAction
itself. I would’ve expected I’d need to also add something like
polymorphic(ServerAction::class) {
subclass(SpecificServerAction::class, SpecificServerAction.serializer())
}
And then somehow tell polymorphic(Action::class)
about it, since ServerAction
is also a subclass of Action
.
But that’s not possible I suppose. In my mind that’s what would have made the most sense 😄
Tell Action about all of its subclasses. Tell ServerAction about all of its subclasses as well. And then inform Action that ServerAction is one of them too.ephemient
07/12/2022, 5:29 PMpolymorphic(Action::class) {
subclass(SpecificServerAction::class, SpecificServerAction.serializer())
}
polymorphic(ServerAction::class) {
subclass(SpecificServerAction::class, SpecificServerAction.serializer())
}
Stylianos Gakis
07/12/2022, 5:42 PMephemient
07/12/2022, 5:44 PM