https.onCall triggers incorrectly encode Date objects as {}.
The docs say that anything JSON encodable should work. In standard implementations Date encodes to an ISO string e.g 2018-09-10T04:07:08.901Z. While this is a one way encoding I think it would be reasonable behaviour.
firebase-functions: master
firebase-tools: N/A
firebase-admin: N/A
export const listener = functions.https.onCall(async (data, context) => {
return { date: new Date() };
}
Yes
Date is encoded as an ISO string, timestamp or using a custom Date encoding.
Date is encoded as {}
@bklimt Would you mind taking a look?
Hi. Thank you for this feedback. It seems the documentation could be clearer. Dates are not yet supported at this time. We are investigating the right way to support them, and may add support in the future. For now, I'd recommend encoding them as strings or numbers yourself as a workaround.
Is a better default behaviour possible than sending an empty object?
At the moment if (res.date) { /*...*/ } executes which gets around some high level checks.
Or could you potentially add a warning when the function executes?
Edit: Noticed the reference has more extensive documentation.
I think, this issue should be closed.
Why don't you fix this with just if _.isDate(data) { return data.toJSON() } as proposed here https://stackoverflow.com/questions/53520674/returning-dates-server-timestamps-in-cloud-callable-functions ?