firebase-kotlin-sdk icon indicating copy to clipboard operation
firebase-kotlin-sdk copied to clipboard

[Issue] ServerTimestamp not working

Open marcelpallares opened this issue 1 year ago • 4 comments
trafficstars

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!

marcelpallares avatar Nov 05 '24 16:11 marcelpallares