Is it possible to register serializer modules with...
# kvision
Is it possible to register serializer modules with kvision rpc?
No. Currently it's not possible.
Crud. That pretty much tanks me. I have some reasonably complex data that leverages serialization modules.
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?
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.
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.
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
from client code, passing those in turn as a constructor parameter to
, and then from there passing them into the
function, which would then instantiate
with that value.
would need to change into a
Please see draft PR for discussion.
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
and JS service constructor)
👍 1
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
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
function on the server side. Alternatively I've created a global Json configuration similar to this one: 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.
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?
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
Tried 5.8.0 with this feature and it works great on my data model. Thanks!