hilla icon indicating copy to clipboard operation
hilla copied to clipboard

Endpoint method invoked with incorrect parameters if JSON keys are not in a certain order

Open Artur- opened this issue 2 years ago • 4 comments

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

Artur- avatar Mar 22 '22 09:03 Artur-

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?

platosha avatar Mar 22 '22 12:03 platosha

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?

Artur- avatar Mar 22 '22 12:03 Artur-

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?

Artur- avatar Mar 23 '22 08:03 Artur-

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.

platosha avatar Apr 04 '22 18:04 platosha