Kotlin / kotlinx-rpc

Add asynchronous RPC services to your multiplatform applications.
https://kotlin.github.io/kotlinx-rpc/
Apache License 2.0
719 stars 16 forks source link

Other serialization library then kotlinx.serialize #142

Closed CheeseTastisch closed 2 months ago

CheeseTastisch commented 2 months ago

Is there some way of using another serialization library then kotlinx.serialize?

For example jackson or gson? With e.g. ktor there is such possibility. It would be nice to have the same possibility with kotlinx.rpc.

Mr3zee commented 2 months ago

Hi! Thank you for the question. No, now we don't have such possibility, add we have no such plans for the nearest future

CheeseTastisch commented 2 months ago

I think that this is an very imporantant feature.

As currently, you can not for example use Result<String> as a return type for a rpc method, as the class is not supported by kotlinx.serialization. So how would you propose to handle a method that can result in an error?

ShayOinif commented 2 months ago

Try and create your own serializable version of result. Don't know if it can take generic.

Taking from other rpc libs, like grpc, you can use status with enums and message to describe success or not.

Further more you can wrap your status with a class that holds the value of the operation if successful or null if not and a status field which indicates with enum the type of error and error message.

Usually you convert throwable to status by classifying the type of error and taking the message from the throwable as the status message.

ShayOinif commented 2 months ago

Moreover, it will be better to make your result return value as cross platform as possible so you won't be confined only to Kotlin with your api, so insisting on result might be less optimal as in the future protocol layer might be separated and you could use your api from different platforms and languages.

CheeseTastisch commented 2 months ago

It was just an examle, however, i personaly do like jackson more than kotlinx.serialization, as i think it is more intuative and integrates beter with existing code and third party libraries.

Mr3zee commented 2 months ago

@CheeseTastisch one way to serialize Result right now is to use this trick in pair with contextual serializers

However we might come up with a better api. When you define serialization scheme, you can pass SerializerModule with different contextual serializers. However, this would not work if Result is a return type or a type of an argument (only work inside other classes, like a property that is marked @Contextual). This is an issue indeed and we will provide support for such cases.

CheeseTastisch commented 2 months ago

Ok, thanks. For now i just created my own Result (see #143). However with it, some errors are still occouring. Don't know, why exactly they occour...