Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue] ServerTimestamp not working #666

Open
marcelpallares opened this issue Nov 5, 2024 · 4 comments
Open

[Issue] ServerTimestamp not working #666

marcelpallares opened this issue Nov 5, 2024 · 4 comments

Comments

@marcelpallares
Copy link

I'm trying to use ServerTimestamp on one of my entity data classes from Firestore. I have tried following what the README says and I added the Timestamp like:

@Serializable
data class Post(
    val timestamp: Timestamp = Timestamp.ServerTimestamp,
)

However, the code complains because ServerTimestamp is not a Timestamp but a BaseTimestamp. Instead, I have tried using:

@Serializable
data class Post(
    val timestamp: BaseTimestamp = Timestamp.ServerTimestamp,
)

The BaseTimestamp approach seems to be working to read existing data, however, when trying to write a new ServerTimestamp I'm getting the following runtime exception:

Caused by: java.lang.RuntimeException: No properties to serialize found on class dev.gitlive.firebase.firestore.Timestamp$ServerTimestamp
    at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.<init>(CustomClassMapper.java:738)
    at com.google.firebase.firestore.util.CustomClassMapper.loadOrCreateBeanMapperForClass(CustomClassMapper.java:383)
    at com.google.firebase.firestore.util.CustomClassMapper.serialize(CustomClassMapper.java:184)
    at com.google.firebase.firestore.util.CustomClassMapper.access$400(CustomClassMapper.java:58)
    at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.serialize(CustomClassMapper.java:926)
    at com.google.firebase.firestore.util.CustomClassMapper.serialize(CustomClassMapper.java:185)
    at com.google.firebase.firestore.util.CustomClassMapper.serialize(CustomClassMapper.java:108)
    at com.google.firebase.firestore.util.CustomClassMapper.convertToPlainJavaTypes(CustomClassMapper.java:82)
    at com.google.firebase.firestore.UserDataReader.convertAndParseDocumentData(UserDataReader.java:232)
     at com.google.firebase.firestore.UserDataReader.parseMergeData(UserDataReader.java:88)
    at com.google.firebase.firestore.DocumentReference.set(DocumentReference.java:166)

Am I doing something wrong here? Is this a known issue?
Thanks!

@mattegoghero
Copy link

Having the same problem, can't use the ServerTimestamp as written in the documentation

@nbransby
Copy link
Member

nbransby commented Dec 2, 2024

@Daeda88 do you know the issue here?

@Daeda88
Copy link
Contributor

Daeda88 commented Dec 2, 2024

Not sure why it's wrong. I see we just use BaseTimestamp, from what it looks like also to write. But perhaps there is a bug.

@Daeda88
Copy link
Contributor

Daeda88 commented Dec 2, 2024

In the test I see we have:
doc.set(FirestoreTimeTest.serializer(), FirestoreTimeTest("ServerTimestampBehavior", Timestamp.ServerTimestamp))

@marcelpallares can you try passing the Post.serializable() to doc.set?

EDIT: Also the crashlogs seem to be serializing at the Google firestore implementation. Are you sure you're calling dev.gitlive.firebase.firestore.DocumentReference.set? In any case it looks like the Timestamp reaches the internal Android SDK as the Gitlive timestamp rather than the google one (which is should have been encoded as). My best guess is that passing the serializer fixes that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants