-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide the option of passing custom Serializers
- Loading branch information
Showing
4 changed files
with
22 additions
and
11 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
lib/src/main/java/de/sipgate/federmappe/DefaultSerializersModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package de.sipgate.federmappe | ||
|
||
import de.sipgate.federmappe.serializers.DateSerializer | ||
import de.sipgate.federmappe.serializers.UriSerializer | ||
import kotlinx.serialization.modules.SerializersModule | ||
import kotlinx.serialization.modules.contextual | ||
|
||
val DefaultSerializersModule = SerializersModule { | ||
contextual(DateSerializer) | ||
contextual(UriSerializer) | ||
} |
7 changes: 5 additions & 2 deletions
7
lib/src/main/java/de/sipgate/federmappe/DocumentSnapshotExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package de.sipgate.federmappe | ||
|
||
import com.google.firebase.firestore.DocumentSnapshot | ||
import kotlinx.serialization.modules.SerializersModule | ||
|
||
inline fun <reified T : Any> DocumentSnapshot.toObject(errorHandler: (Throwable) -> T? = { throw it }): T? = | ||
inline fun <reified T : Any> DocumentSnapshot.toObject( | ||
customSerializers: SerializersModule = DefaultSerializersModule, | ||
errorHandler: (Throwable) -> T? = { throw it }): T? = | ||
try { | ||
data?.toObjectWithSerializer<T>() | ||
data?.toObjectWithSerializer<T>(customSerializers = customSerializers) | ||
} catch (ex: Throwable) { | ||
errorHandler(ex) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters