Skip to content

[Feature Request][Firebase Database] Parse Date object automatically #3640

Open
@risalfajar

Description

@risalfajar

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions