firebase-android-sdk
firebase-android-sdk copied to clipboard
[Feature Request][Firebase Database] Parse Date object automatically
What feature would you like to see?
Currently, if we have a Date object in our data class:
data class Message(
val id: String = "",
val sentAt: Date = Date(),
val sentBy: String = "",
val text: String = "",
)
Then use getValue:
val message = snapshot.getValue(Message::class.java)
It will throw an exception:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.iexample.app, PID: 9218
com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.Long to type java.util.Date
This does not happen in Firestore, the object mapper can map a Timestamp to a Date without any problem.
I get that in Firebase Database a Date is stored as a Long, but we can convert it easily like this Date(timeInMillis). I hope that this conversion is implemented in the mapper so that we don't need to do any workaround or convert it manually.
How would you use it?
Usage doesn't change of course.
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Hi @risalfajar, thanks for filing a request. Our engineers will be able to take a look at this once they have the time.