Is it possible to register serializer modules with...
# kvision
r
Is it possible to register serializer modules with kvision rpc?
r
No. Currently it's not possible.
r
Crud. That pretty much tanks me. I have some reasonably complex data that leverages serialization modules.
r
Please fill an issue on github
If I understand correctly you have written custom serializers/deserializers for your data?
both on the JS and JVM targets?
r
A couple, but mainly its modules that declare polymorphic serializers.
Yes, in common code
There are some severe limitations / issues with kotlinx.serialization with closed polymorphism so I don't have a choice, even though I actually am dealing with closed polymorphism.
r
Please give some examples in the issue.
I think it could be done as I'm already registering serializers for kvision types. I just need to find some nice way to add external serializers.
r
I could register them with Guice as a Set binding (or whatever the equivalent is in Guice).
Alternatively I could pass them in to kvisionInit
The latter would actually be my preference, as I don't use Guice myself
Looking at the code, it definitely seems doable by passing the module(s) into the constructor of
KVServiceManager
from client code, passing those in turn as a constructor parameter to
KVServiceBinder
, and then from there passing them into the
kotlinxObjectDeSerializer()
function, which would then instantiate
KotlinxObjectDeSerializer
with that value.
KotlinxObjectDeSerializer
would need to change into a
class
though.
Please see draft PR https://github.com/rjaros/kvision/pull/343 for discussion.
r
Thanks! Just looking at it.
Why a list of modules, when you can always combine them into a single one?
I don't think it can be done the way you proposed. KVServiceManager is instantiated by the code generated with a plugin and there is no simple way to pass serializers module without some serious rewrite of the compiler plugin.
🆗 1
I think I'll try a different path (passing modules to
kvisionInit()
and JS service constructor)
👍 1
r
Multiple simply because the caller may define several modules for different aspects of their model, and being able to take a list is helpful since the caller doesn't have to combine them before passing them into KVision. Same reason we take multiple Guice modules I guess.
My initial thought was kvisionInit as well, but I couldn't figure out how to connect it up from there
r
Done. I've refactored a lot of serialization code. I've separated old code we have talked about a few months ago into a separate class, used only with legacy compiler. Unfortunately this is still required for legacy, because standard serialization functions fail with strange exceptions - see KT-41282. For IR there are no problems, so the serialization code is now clean and external serialization modules can be easily applied. I hope you work with IR 🙂
There are two methods of using custom serialization modules. You can pass a list of modules as parameter to client side service constructor on the client side and as the parameter to the
applyRoutes()
function on the server side. Alternatively I've created a global Json configuration similar to this one: https://github.com/rjaros/kvision/issues/324 You wil be able to set
RemoteSerializaton.customConfiguration = ...
even in the common module and it will be automatically applied to both client and server serialization.
r
That sounds amazing @Robert Jaros (yes, I do use IR). Is there a snapshot version I can try somewhere, or should I build it locally and give it a shot?
r
You can try building locally but I will probably release 5.8.0 later today. I just have to rebuild and test all my real applications to be sure nothing is seriously broken 😉
👍 1
r
Tried 5.8.0 with this feature and it works great on my data model. Thanks!