-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #448 from splendo/feature/serialization-fixes
Adding Serialization fixes
- Loading branch information
Showing
62 changed files
with
2,649 additions
and
1,394 deletions.
There are no files selected for viewing
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
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
70 changes: 70 additions & 0 deletions
70
firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.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,70 @@ | ||
package dev.gitlive.firebase | ||
|
||
import kotlinx.serialization.modules.EmptySerializersModule | ||
import kotlinx.serialization.modules.SerializersModule | ||
|
||
/** | ||
* Settings used to configure encoding/decoding | ||
*/ | ||
sealed class EncodeDecodeSettings { | ||
|
||
/** | ||
* The [SerializersModule] to use for serialization. This allows for polymorphic serialization on runtime | ||
*/ | ||
abstract val serializersModule: SerializersModule | ||
} | ||
|
||
/** | ||
* [EncodeDecodeSettings] used when encoding an object | ||
* @property encodeDefaults if `true` this will explicitly encode elements even if they are their default value | ||
* @param serializersModule the [SerializersModule] to use for serialization. This allows for polymorphic serialization on runtime | ||
*/ | ||
data class EncodeSettings internal constructor( | ||
val encodeDefaults: Boolean, | ||
override val serializersModule: SerializersModule, | ||
) : EncodeDecodeSettings() { | ||
|
||
interface Builder { | ||
var encodeDefaults: Boolean | ||
var serializersModule: SerializersModule | ||
|
||
} | ||
|
||
@PublishedApi | ||
internal class BuilderImpl : Builder { | ||
override var encodeDefaults: Boolean = true | ||
override var serializersModule: SerializersModule = EmptySerializersModule() | ||
} | ||
} | ||
|
||
/** | ||
* [EncodeDecodeSettings] used when decoding an object | ||
* @param serializersModule the [SerializersModule] to use for deserialization. This allows for polymorphic serialization on runtime | ||
*/ | ||
data class DecodeSettings internal constructor( | ||
override val serializersModule: SerializersModule = EmptySerializersModule(), | ||
) : EncodeDecodeSettings() { | ||
|
||
interface Builder { | ||
var serializersModule: SerializersModule | ||
} | ||
|
||
@PublishedApi | ||
internal class BuilderImpl : Builder { | ||
override var serializersModule: SerializersModule = EmptySerializersModule() | ||
} | ||
} | ||
|
||
interface EncodeDecodeSettingsBuilder : EncodeSettings.Builder, DecodeSettings.Builder | ||
|
||
@PublishedApi | ||
internal class EncodeDecodeSettingsBuilderImpl : EncodeDecodeSettingsBuilder { | ||
|
||
override var encodeDefaults: Boolean = true | ||
override var serializersModule: SerializersModule = EmptySerializersModule() | ||
} | ||
|
||
@PublishedApi | ||
internal fun EncodeSettings.Builder.buildEncodeSettings(): EncodeSettings = EncodeSettings(encodeDefaults, serializersModule) | ||
@PublishedApi | ||
internal fun DecodeSettings.Builder.buildDecodeSettings(): DecodeSettings = DecodeSettings(serializersModule) |
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
Oops, something went wrong.