Backend communication and manually serializing data

When sending the following data from the frontend to a backend service only the first object in the array is received:

const data = [{name: 'abc'}, {name: 'def'}];
this.helloBackendService.sayHelloTo(data)
// backend service only receieves: {name: 'abc'}

But when I send the same data from the backend to the frontend the data arrives intact:

const data = [{name: 'abc'}, {name: 'def'}];
return data;
// frontend service receieves: [{name: 'abc'}, {name: 'def'}]

So I’m not sure when it’s expected to use JSON.stringify() to send and JSON.parse() to receive or whether there’s a bug?

Hi @jweb,

  1. Could you open an issue, please?
  2. Are you saying that returning arrays from a function works, but passing arrays as a parameter does not? Or are you saying passing array parameters works in one direction but not in the other?

Also, are you talking about regular Theia back end services like CommandService or a main/ext service connection used to implement plugin interfaces (Like CommandRegistryImpl)?

  1. Are you saying that returning arrays from a function works, but passing arrays as a parameter does not? Or are you saying passing array parameters works in one direction but not in the other?

Yes. When I returned an array from one method in the service I got the array, but when sending the same array back to another method in that service only the first element arrived (but if I first converted the array with JSON.stringify all of the array was contained in the received string).

It was from an extension I’m developing. I just tried to reproduce it using the backend template generated by ‘yo theia-extension’ but that worked as expected. I’ll try to figure out why it’s working differently in my extension and will post an update then.

This could be related.

Thanks, yes it seems to be the same issue. I couldn’t reproduce it originally because it doesn’t happen when the first parameter is a string.

const testData: MyTestData = [{name: "abc"}, {name: "def"}, {name: "ghi"}];

// The array is received
const returnedData1 = await this.testServiceA.sendDataToAndGetDataFromA('World', testData);

// Only the first element is received
const returnedData2 = await this.testServiceB.sendDataToAndGetDataFromB(testData);

I’ve just finished reproducing it in an example extension so have added it to the issue.