I’m attempting to use a Realm function in my Kotlin Android application, but I’m getting the error ‘Could not resolve encoder for end type’.
Here is where I’m calling the function:
val completableDeferred = CompletableDeferred<App.Result<Document>>()
val functions: Functions = app.getFunctions(app.currentUser())
//user.email and user.name are strings
functions.callFunctionAsync("assignNewUser", listOf(user.email, user.name), Document::class.java){
completableDeferred.complete(it)
}
Also, a side-note. I’m calling this function after I’ve registered a user, because I haven’t found a way to register a user while passing in extra parameters like a name or a profile picture. I’m registering users using the App.emailPassword.registerUserAsync(email, password) method.
Curiously, when I try to run a function like this, I hit no problems. It’s a little tricky without seeing the code for completableDeferred or your imports, but I would guess that you’re using the wrong type of Document. Check the imports at the top of your file for:
import org.bson.Document
If you’ve imported some other kind of Document class, Realm probably won’t know how to write data into that class. Let me know if this works!
Thanks for the reply. The Document I’m using is in fact an org.bson.Document.
The rest of the Kotlin code is here, sorry, I didn’t think it relevant.
val result = completableDeferred.await()
if (!result.isSuccess) {
val exception = RegisterException()
result.error.errorMessage?.let { exception.errorMessage = it }
throw exception
}
What version of the Realm Android SDK are you using? I just tried with 10.0.0 and 10.3.1 with mostly the same code as you provided here and I didn’t have any issues.
The RegisterException is my own, of type Throwable and has an errorMessage val.
But, quite strangely my error has changed to FunctionError: update not permitted. No idea why, I haven’t changed anything! I would assume my User needs to have the permission, where would I set this?
That’s largely dependent on your app, but you can get started by reading up on permissions here. You can also check out some example query roles here. Depending on your application you might not need anything other than allowing all reads and writes to a specific collection in a specific database.