-
Notifications
You must be signed in to change notification settings - Fork 1
add dynamic params textbox #13
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
Conversation
| @JvmStatic | ||
| suspend fun getRaw(name: String, params: String?): Result<Map<String, Any?>> { | ||
| return withContext(Dispatchers.IO) { | ||
| val res = getNative(name, params) | ||
| if (res.status != 0) { | ||
| return@withContext Result.failure(parseOpacityError(res.err)) | ||
| } | ||
|
|
||
| val map: Map<String, Any?> = | ||
| Json.parseToJsonElement(res.data!!).jsonObject.mapValues { | ||
| parseJsonElementToAny(it.value) | ||
| } | ||
|
|
||
| return@withContext Result.success(map) | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed a new function because, funny enough, when trying to Json.encodeToString(), it would crash the app because Any can not be serialized. (line 137 - val paramsString = params?.let { Json.encodeToString(it) })
Am I doing something wrong here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? what did you try to pass. But in any case Json.encodeToString() is kinda basic, you can see on the JsonToAnyConverter I had to write custom logic to create generic JSON from a string. You probably will need to write the inverse or just pass the raw string after doing your validation? Not sure what you tried to pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to pass {"previous_response": ""} to it
I even modified my function to use the JsonToAnyConverter.parseJsonElementToAny:
val paramsValue = if (params == null) null else {
val parsed = kotlinx.serialization.json.Json.parseToJsonElement(
params
)
parsed.jsonObject.entries.map { (key, value) ->
key to JsonToAnyConverter.parseJsonElementToAny(
value
)
}.toMap()
}
val res = OpacityCore.get(
flowInput.value,
paramsValue
)And it is still crashing on what it was crashing before
I would probably need to write logic for doing the inverse Any to actual JSON.
I was thinking trying to parse it and validating and then giving the raw string directly would be better? The way I've done in the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just took a look at it seems I made the mistake. A Map<String, Any>? is not serializable by kotlinx.serialization. It seems the library is really following the Java philosphy of only working with objects/classes, so it cannot convert Any... terrible
I'm taking a look to see if there is anyway it can take a Map<String, Any> before serializing it
nerodesu017
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.