From c24dbd81ff742a7299864d3e57c61a2516432d00 Mon Sep 17 00:00:00 2001 From: Zhirkevich Alexander Y Date: Tue, 23 Jul 2024 10:07:35 +0300 Subject: [PATCH] fix unsupported effects serialization --- .../internal/animation/AnimatedVectorN.kt | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/compottie/src/commonMain/kotlin/io/github/alexzhirkevich/compottie/internal/animation/AnimatedVectorN.kt b/compottie/src/commonMain/kotlin/io/github/alexzhirkevich/compottie/internal/animation/AnimatedVectorN.kt index 17090729..d1ce3936 100644 --- a/compottie/src/commonMain/kotlin/io/github/alexzhirkevich/compottie/internal/animation/AnimatedVectorN.kt +++ b/compottie/src/commonMain/kotlin/io/github/alexzhirkevich/compottie/internal/animation/AnimatedVectorN.kt @@ -9,10 +9,14 @@ import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.Transient +import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.builtins.serializer import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.JsonContentPolymorphicSerializer import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.JsonTransformingSerializer import kotlinx.serialization.json.intOrNull import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive @@ -22,7 +26,6 @@ import kotlin.math.min @Serializable(with = AnimatedVectorNSerializer::class) internal sealed class AnimatedVectorN : DynamicProperty>() { - override fun mapEvaluated(e: Any): List { return when (e) { is List<*> -> e as List @@ -36,6 +39,7 @@ internal sealed class AnimatedVectorN : DynamicProperty>() { @Serializable class Default( @SerialName("k") + @Serializable(with = ToListSerializer::class) val value: List, @SerialName("x") @@ -49,9 +53,6 @@ internal sealed class AnimatedVectorN : DynamicProperty>() { prepare() } - @Transient - private val vec = Vec2(value[0], value[1]) - override fun raw(state: AnimationState): List = value override fun copy(): AnimatedVectorN { @@ -107,6 +108,8 @@ internal sealed class AnimatedVectorN : DynamicProperty>() { } } + + internal class AnimatedVectorNSerializer : JsonContentPolymorphicSerializer(AnimatedVectorN::class) { override fun selectDeserializer(element: JsonElement): DeserializationStrategy { @@ -123,3 +126,13 @@ internal class AnimatedVectorNSerializer : JsonContentPolymorphicSerializer>(ListSerializer(Float.serializer())){ + override fun transformDeserialize(element: JsonElement): JsonElement { + return if (element is JsonPrimitive){ + JsonArray(listOf(element)) + } else { + element + } + } +} \ No newline at end of file