You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to create a Service with a nullable return type recently, which, (as the docs point out) doesn't work. So i used a wrapper like this:
@Serializable
classMyOptional<T>(
valvalue:T?
) // Can't use java optionals
Now i thought: would it be possible to automatically generate code for wrapper functions that utilize a wrapper like this one, but internally call methods with normal nullable return type.
Would this be an appreciated contribution, and if so has anyone any code pointers on where to start?
The text was updated successfully, but these errors were encountered:
It's quite difficult to answer your question and I'm not even sure I'm able to explain. KVision server side interfaces code is based on inline functions and reified type parameters. It is required because at the deepest level kotlinx.serialization library is used to serialize and deserialize generic data. And almost all serialization functions are defined for T : Any types, which excludes nullable types. And because of the nature of inline functions, that exclusion is popping to the top and makes it impossible to use nullable types at the Service level. With the help of casting and some "dirty hacks" I've implemented nullability for parameters of methods. But as I don't have control over the returned data, there is no way to do the same for deserialization of the results. And that's the reason of the current limitation.
But it's not the end of the story, because where was no compiler plugin when all of this was implemented. Now, with the help of compiler plugin it should be possible to generate some kind of a wrapper. But I'm afraid it would require much work. Currently the plugin operates on the very simple level - it basically works with strings manipulation. I think it would be required to deeply analyze Kotlin code inside the plugin code to generate working wrapper. Unfortunately the compiler plugin API is not documented so it would require a lot of work, trials and errors. I would really appreciate the contribution, but I will definitely understand if you find that the effect is not worth the effort :-)
I wanted to create a Service with a nullable return type recently, which, (as the docs point out) doesn't work. So i used a wrapper like this:
Now i thought: would it be possible to automatically generate code for wrapper functions that utilize a wrapper like this one, but internally call methods with normal nullable return type.
Would this be an appreciated contribution, and if so has anyone any code pointers on where to start?
The text was updated successfully, but these errors were encountered: