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
packagemodelsimportandroidx.compose.runtime.MutableStateimportandroidx.compose.runtime.mutableStateListOfimportandroidx.compose.runtime.snapshots.SnapshotStateListimportkotlinx.serialization.KSerializerimportkotlinx.serialization.Serializableimportkotlinx.serialization.builtins.ListSerializerimportkotlinx.serialization.descriptors.SerialDescriptorimportkotlinx.serialization.encoding.Decoderimportkotlinx.serialization.encoding.Encoder
@Serializable
data classServer(
varid:Int,
varname:MutableState<String>,
@Serializable(with=SnapshotListSerializer::class) varurls:SnapshotStateList<Address>
)
classSnapshotListSerializer<T>(privatevaldataSerializer:KSerializer<T>) :
KSerializer<SnapshotStateList<T>> {
overrideval descriptor:SerialDescriptor=ListSerializer(dataSerializer).descriptor
overridefunserialize(encoder:Encoder, value:SnapshotStateList<T>) {
encoder.encodeSerializableValue(ListSerializer(dataSerializer), value asList<T>)
}
overridefundeserialize(decoder:Decoder): SnapshotStateList<T> {
val list = mutableStateListOf<T>()
val items = decoder.decodeSerializableValue(ListSerializer(dataSerializer))
list.addAll(items)
return list
}
}
I was expecting to serialize/deserialize the SnapshotStateList, and a serializer was set, but I got an error
How do I fix this?
Exception in thread "AWT-EventQueue-0" kotlinx.serialization.SerializationException: Serializer for subclass 'SnapshotMutableStateImpl' is not found in the polymorphic scope of 'MutableState'.
Check if class with serial name 'SnapshotMutableStateImpl' exists and serializer is registered in a corresponding SerializersModule.
To be registered automatically, class 'SnapshotMutableStateImpl' has to be '@Serializable', and the base class 'MutableState' has to be sealed and '@Serializable'.
at kotlinx.serialization.internal.AbstractPolymorphicSerializerKt.throwSubtypeNotRegistered(AbstractPolymorphicSerializer.kt:102)
at kotlinx.serialization.internal.AbstractPolymorphicSerializerKt.throwSubtypeNotRegistered(AbstractPolymorphicSerializer.kt:114)
at kotlinx.serialization.PolymorphicSerializerKt.findPolymorphicSerializer(PolymorphicSerializer.kt:109)
at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:242)
at kotlinx.serialization.encoding.AbstractEncoder.encodeSerializableElement(AbstractEncoder.kt:80)
at models.Server.write$Self$TsTeA(Server.kt:16)
at models.Server$$serializer.serialize(Server.kt:16)
at models.Server$$serializer.serialize(Server.kt:16)
at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:249)
at kotlinx.serialization.encoding.AbstractEncoder.encodeSerializableElement(AbstractEncoder.kt:80)
at kotlinx.serialization.internal.CollectionLikeSerializer.serialize(CollectionSerializers.kt:69)
at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:249)
at kotlinx.serialization.json.internal.JsonStreamsKt.encodeByWriter(JsonStreams.kt:31)
at kotlinx.serialization.json.Json.encodeToString(Json.kt:81)
at pages.mainpage.MainPageKt$MainPage$1$1$2$1$3.invoke(MainPage.kt:98)
at pages.mainpage.MainPageKt$MainPage$1$1$2$1$3.invoke(MainPage.kt:49)
......
The text was updated successfully, but these errors were encountered:
I was expecting to serialize/deserialize the SnapshotStateList, and a serializer was set, but I got an error
How do I fix this?
The text was updated successfully, but these errors were encountered: