Skip to content

Commit

Permalink
Add toObject extension functions
Browse files Browse the repository at this point in the history
  • Loading branch information
janseeger committed Dec 21, 2023
1 parent 75f077f commit 7bc983b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/src/main/java/de/sipgate/federmappe/DocumentSnapshotExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package de.sipgate.federmappe

import com.google.firebase.firestore.DocumentSnapshot

inline fun <reified T : Any> DocumentSnapshot.toObject(errorHandler: (Throwable) -> T? = { throw it }): T? =
try {
data?.toObjectWithSerializer<T>()
} catch (ex: Throwable) {
errorHandler(ex)
}
12 changes: 12 additions & 0 deletions lib/src/main/java/de/sipgate/federmappe/QuerySnapshotExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package de.sipgate.federmappe

import com.google.firebase.firestore.QuerySnapshot

inline fun <reified T : Any> QuerySnapshot.toObject(errorHandler: (Throwable) -> T? = { throw it }): List<T?> =
map {
try {
it.data.toObjectWithSerializer()
} catch (ex: Throwable) {
errorHandler(ex)
}
}

0 comments on commit 7bc983b

Please sign in to comment.