how do you conditionally deserialize one field bas...
# serialization
e
how do you conditionally deserialize one field based on the value of an already deserialized one?
e
Have you found an answer BTW? I'm curious too.
e
not as I hope at the moment I simply fallen back to have default nullable values, which works luckily for my case but it's not optimal the only proper solution so far, is to simply write your own serializer, ie
Copy code
object EventTypeSerializer : KSerializer<EventType> {
    override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("java.time.Instant", PrimitiveKind.STRING)
    override fun serialize(encoder: Encoder, value: EventType) = TODO()
    override fun deserialize(decoder: Decoder): EventType = EventType of decoder.decodeString()
}
and then
@file:UseSerializers(EventTypeSerializer::class)
where you need, but this defy the point of using a JSON parser in the first place..
e
Yeah I don't think this feature exists in the library, maybe worth opening an issue on GitHub?
e
probably, but I need time 😞