commonMain.dev.gitlive.firebase.internal.serializers.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of firebase-common-internal-jvm Show documentation
Show all versions of firebase-common-internal-jvm Show documentation
The Firebase Kotlin SDK is a Kotlin-first SDK for Firebase. It's API is similar to the Firebase Android SDK Kotlin Extensions but also supports multiplatform projects, enabling you to use Firebase directly from your common source targeting iOS, Android or JS.
/*
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
*/
package dev.gitlive.firebase.internal
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerializationException
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.StructureKind
import kotlinx.serialization.descriptors.buildClassSerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.serializer
@Suppress("UNCHECKED_CAST")
public inline fun T.firebaseSerializer(): SerializationStrategy = runCatching { serializer() }
.getOrElse {
when (this) {
is Map<*, *> -> FirebaseMapSerializer()
is List<*> -> FirebaseListSerializer()
is Set<*> -> FirebaseListSerializer()
else -> this::class.serializer()
} as SerializationStrategy
}
public class FirebaseMapSerializer : KSerializer