Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RpcDefault only has default converters for boxed types, not primitives (e.g. Boolean not boolean) #138

Open
sbrocket opened this issue Jun 21, 2024 · 0 comments
Assignees

Comments

@sbrocket
Copy link

I discovered on my first usage of @RpcDefault that mobly-snippet-lib only has default type converters defined for the boxed types like Boolean, but not boolean. This ends up particularly confusing when writing snippets in Kotlin because Kotlin's "Boolean" is a JVM "boolean" primitive.

For example, the following naive Kotlin conversion of ex7_default_and_optional_rpc:

    @Rpc(description = "Make a toast on screen.")
    fun makeToast(
            message: String, @RpcDefault("true") bool: Boolean, @RpcOptional number: Int): String {

will result in the following unless a value is provided for "bool":

java.lang.IllegalArgumentException: No predefined converter found for boolean
	at com.google.android.mobly.snippet.rpc.MethodDescriptor.converterFor(MethodDescriptor.java:309)
	at com.google.android.mobly.snippet.rpc.MethodDescriptor.getDefaultValue(MethodDescriptor.java:280)
	at com.google.android.mobly.snippet.rpc.MethodDescriptor.invoke(MethodDescriptor.java:91)
	at com.google.android.mobly.snippet.util.RpcUtil.invokeRpc(RpcUtil.java:131)
	at com.google.android.mobly.snippet.util.RpcUtil.invokeRpc(RpcUtil.java:103)
	at com.google.android.mobly.snippet.rpc.JsonRpcServer.handleRPCConnection(JsonRpcServer.java:83)
	at com.google.android.mobly.snippet.rpc.SimpleServer$ConnectionThread.run(SimpleServer.java:109)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants