1
votes

I have a field in Firestore which is of type "Timestamp". I am able to store the value in Firestore using either the java "Date" type or the java Firebase "Timestamp" types. The field is stored in Firebase successfully as the "Timestamp" type.

When I try to send the value back to the client from the server using GCM, I get the following error:

java.text.ParseException: Unparseable date: "[object Object]"

I have logged out the RemoteMessage.getData(), notice the "createdAt" field, this is the TimeStamp that is giving the parsing error.

{userId=someValue, id=someValue, iv=someValue, text=someValue, createdAt=[object Object]}

How can I handle the parsing of this Timestamp field?

FYI: here is the nodejs code that creates the GCM notification:

data: {
    id:        `${id}`,
    userId:    `${userId}`,
    text:      `${text}`,
    createdAt: `${createdAt}`,
    iv:        `${iv}`
}
1
What works best for me is converting the date + time to json.danwillm
You mean converting before i send to firestore? storing it as type "String", as a string of json? Or do you mean keeping the TimeStamp and converting it just before I send it back to the client (in the cloud function)?brux
Convert it to json - it will store it as a timestamp in firestore.danwillm
I dont think that's the problem, the field is already being stored just fine as type TimeStamp in Firestore. I'm going to convert it to milliseconds in my cloud function before sending it back to the client using toMillis(), and then in the client I will parse the milliseconds into a Date object.brux
Have you tried using json to upload it to the server?danwillm

1 Answers

0
votes

Timestamp objects are not just a simple integer value like other Date types. As you can see from the API documentation, they have a seconds nanoseconds component, and that doesn't have a standard string representation. If you want something simpler, you'll have to compose that on your own. Perhaps toMillis() will work OK, but you'll possibly be losing nanoseconds precision.