one more try to fix nosuchelement exception

This commit is contained in:
2022-05-18 15:33:26 +06:00
parent 6c094f3ad9
commit dd369177c1
11 changed files with 27 additions and 74 deletions
features
auth
client
src
commonMain
kotlin
dev
inmo
postssystem
jsMain
kotlin
dev
inmo
postssystem
features
auth
common
src
commonMain
kotlin
dev
inmo
postssystem
features
auth
common
client
src
commonMain
kotlin
dev
inmo
postssystem
features
common
common
roles
common
src
commonMain
kotlin
dev
inmo
postssystem
features
roles
common
manager
common
src
commonMain
kotlin
dev
inmo
postssystem
features
roles
manager
server
src
jvmMain
kotlin
dev
inmo
gradle
targets/telegram/loader/server/src/jvmMain/kotlin/dev/inmo/postssystem/targets/telegram/loader/server

@ -8,7 +8,6 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlin.jvm.JvmInline
@Serializable(AuthKeySerializer::class)
sealed interface AuthKey
@Serializable
@ -18,34 +17,6 @@ private data class AuthKeySurrogate(
val refreshToken: RefreshToken?
)
@Serializer(AuthKey::class)
object AuthKeySerializer : KSerializer<AuthKey> {
override val descriptor: SerialDescriptor
get() = AuthKeySurrogate.serializer().descriptor
override fun deserialize(decoder: Decoder): AuthKey {
val surrogate = AuthKeySurrogate.serializer().deserialize(decoder)
when {
surrogate.authCreds != null -> return surrogate.authCreds
surrogate.token != null -> return surrogate.token
surrogate.refreshToken != null -> return surrogate.refreshToken
}
error("Unsupported version of auth key surrogate")
}
override fun serialize(encoder: Encoder, value: AuthKey) {
AuthKeySurrogate.serializer().serialize(
encoder,
AuthKeySurrogate(
value as? AuthCreds,
value as? AuthToken,
value as? RefreshToken
)
)
}
}
@Serializable
@SerialName("authcreds")
data class AuthCreds(