Closed gchristov closed 2 months ago
Also, worth noting that normal object serialisation works. I'm seeing the issue with sealed
classes only.
As a workaround I've added a custom serializer which converts to/from String
.
private object SessionStateSerializer : KSerializer<ApiSearchSession.State> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(
serialName = "ApiSearchSession.State",
kind = PrimitiveKind.STRING
)
override fun deserialize(decoder: Decoder): ApiSearchSession.State {
return Json.decodeFromString(decoder.decodeString())
}
override fun serialize(
encoder: Encoder,
value: ApiSearchSession.State
) {
encoder.encodeString(Json.encodeToString(value))
}
}
and am using it on the property directly like
@Serializable(with = SessionStateSerializer::class)
val state: State
I'm trying to serialise/deserialise the following model into Firestore on KotlinJS with
nodeJs()
target, which is correctly written to Firestore, along with its generatedtype
.I'm writing this to Firestore like this
However, when deserialising I'm getting a
ClassCastException
. My deserialisation code isAm I missing something? I've tried serialising the above to/from
String
s with kotlinx.serialisation and it works as it should which lead me to think it's an SDK issue here. I'm on version1.6.2
of the SDK.Thanks in advance! 🙏