hilla
hilla copied to clipboard
Endpoint method invoked with incorrect parameters if JSON keys are not in a certain order
Description of the bug
Calling an endpoint like
@Endpoint
@AnonymousAllowed
public class MyEndpoint {
public String hello(String first, String last) {
return "Hello " + first + " " + last;
}
}
as
Notification.show(await client.call("MyEndpoint", "hello", { "first": "first", "last": "last" }));
or
Notification.show(await client.call("MyEndpoint", "hello", { "last": "last", "first": "first" }));
should produce the same result.
Minimal reproducible example
Above
Actual behavior
In the first case you see "Hello first last", in the second case you see "Hello last first"
Versions:
- Vaadin / Hilla version: 1.0.1
It’s an issue with our protocol:
- OpenAPI schema does not support tuples, so we use object for sending call arguments
- Java runtime ignores the keys in the object, but relies on the order of the values
Any particular use cases for invoking client.call
directly?
It happens for real with the push implementation. Seems like the params
object is re-created at some point before it reaches EndpointInvoker
. Should the params be sent as an array instead?
I made a workaround for push (https://github.com/vaadin/flow/commit/803cc59c9c7c2e4cbb2c9e23b1e555029c3b5a06) so that it ignores the keys and creates an array in the browser and it fixes the problem. Could we just change communication to work this way?
I think we could. Ideally endpoint arguments should be sent as tuples. It’s probably better to not change the OpenAPI spec definition format yet though. So yeah, we could just change the communication for now then.