When I send an object from the client to the server using a Meteor Call and Meteor method, something strange happens. The object is received in the Method but it looks different - nested within the giftList.
Meteor Call - JSON.stringify
{"personName":"Default person name","username":"","gifts":[]}
Meteor Method
{"giftList":{"personName":"Default person name","username":"","gifts":[]}}
Meteor Call Code
console.log(JSON.stringify(giftList)) // {"personName":"Default person name","username":"","gifts":[]}
Meteor.call("addGiftList", {giftList}, (err: any, res) => {});
Meteor Method code
Meteor.methods({
"addGiftList": function (giftList: GiftList): void {
console.log(JSON.stringify(giftList)) // {"giftList":{"personName":"Default person name","username":"","gifts":[]}}
return GiftListCollectionManager.getInstance().insert(giftList);
}
});
GiftList
export class GiftList {
personName: string = "";
username: string = "";
gifts: Gift[] = [];
}
I am puzzled as to why the object appears differently when received. What could be causing this discrepancy and how should it be properly handled?