You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.let { FirebaseCompositeEncoder(shouldEncodeElementDefault, { value = it.chunked(2).associate { (k, v) -> k to v } }) { _, _, value -> it.add(value) } }
Copy file name to clipboardExpand all lines: firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/Polymorphic.kt
+8-3
Original file line number
Diff line number
Diff line change
@@ -16,10 +16,16 @@ internal fun <T> FirebaseEncoder.encodePolymorphically(
16
16
value:T,
17
17
ifPolymorphic: (String) ->Unit
18
18
) {
19
+
// If serializer is not an AbstractPolymorphicSerializer or if we are encoding this as a list, we can just use the regular serializer
20
+
// This will result in calling structureEncoder for complicated structures
21
+
// For PolymorphicKind this will first encode the polymorphic discriminator as a String and the remaining StructureKind.Class as a map of key-value pairs
22
+
// This will result in a list structured like: (type, { classKey = classValue })
19
23
if (serializer !isAbstractPolymorphicSerializer<*>) {
20
24
serializer.serialize(this, value)
21
25
return
22
26
}
27
+
28
+
// When doing Polymorphic Serialization with EncodeDecodeSettings.PolymorphicStructure.MAP we will use the polymorphic serializer of the class.
23
29
val casted = serializer asAbstractPolymorphicSerializer<Any>
24
30
val baseClassDiscriminator = serializer.descriptor.classDiscriminator()
25
31
val actualSerializer = casted.findPolymorphicSerializer(this, value asAny)
@@ -32,15 +38,15 @@ internal fun <T> FirebaseDecoder.decodeSerializableValuePolymorphic(
32
38
value:Any?,
33
39
deserializer:DeserializationStrategy<T>,
34
40
): T {
41
+
// If deserializer is not an AbstractPolymorphicSerializer or if we are decoding this from a list, we can just use the regular serializer
35
42
if (deserializer !isAbstractPolymorphicSerializer<*>) {
36
43
return deserializer.deserialize(this)
37
44
}
38
-
39
45
val casted = deserializer asAbstractPolymorphicSerializer<Any>
40
46
val discriminator = deserializer.descriptor.classDiscriminator()
41
47
val type = getPolymorphicType(value, discriminator)
42
48
val actualDeserializer = casted.findPolymorphicSerializerOrNull(
43
-
structureDecoder(deserializer.descriptor),
49
+
structureDecoder(deserializer.descriptor, false),
44
50
type
45
51
) asDeserializationStrategy<T>
46
52
return actualDeserializer.deserialize(this)
@@ -55,4 +61,3 @@ internal fun SerialDescriptor.classDiscriminator(): String {
0 commit comments