firebase / firebase/firebase-android-sdk
[Feature Request][Firebase Database] Parse Date object automatically
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 710
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 34
Description
## What feature would you like to see?
Currently, if we have a `Date` object in our data class:
```kotlin
data class Message(
val id: String = "",
val sentAt: Date = Date(),
val sentBy: String = "",
val text: String = "",
)
```
Then use `getValue`:
```kotlin
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.
Contributor guide
Assessment
This issue has not been assessed yet.