[FireStore] How to decode Timestamp in Multiplatform Code (Android/iOS)
See original GitHub issueGiven
data class Article(
val title: String = "",
val subTitle: String = "",
val image: String = "",
val date: Double = 0.0,
val content: String = ""
)
Firebase.firestore.collection("articles")
.get()
.documents
.map { doc ->
Article(
doc.get("title"),
doc.get("subTitle"),
doc.get("image"),
doc.get("date"),
doc.get("content")
)
}
When
date
is type timestamp in Firestore.
Then
How do we decode this type in commonMain for example? I have tried setting Article.date to String and Double and both crash.
kotlinx.serialization.SerializationException: Expected Timestamp(seconds=1606944088, nanoseconds=0) to be double
Does the SDK provide any method to help with decoding this automatically?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How do I convert a Firestore date/Timestamp to Date in Kotlin?
I'm using this code: val timestamp = it["time"] as com.google.firebase.Timestamp val milliseconds = timestamp.seconds * 1000 + ...
Read more >Get to know Firebase for Flutter - Google
How to authenticate users with Firebase Authentication and sync data with Firestore. What you'll need.
Read more >Firebase Kotlin SDK
The official Firebase SDKs use different platform-specific ways to support writing data with and without custom classes in Cloud Firestore, Realtime Database ...
Read more >Firebase Realtime Database and Login Tutorial (2022 Update)
It includes ready-made cross-platform code to interact with the Google ... download the Felgo Live app from the app store: Android / iOS....
Read more >Google Codelabs
Google Developers Codelabs provide a guided, tutorial, hands-on coding experience. Most codelabs will step you through the process of building a small ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
What about encoding it ? i.e. adding a date in the where clause Query.where(“updatedDate”, greaterThan = what_to_place_here)
@wezley98 any solution?