Skip to content

Instantly share code, notes, and snippets.

@bitkid
Created June 1, 2022 13:32
Show Gist options
  • Save bitkid/33bf33b8e25d8340d642d86d7c283924 to your computer and use it in GitHub Desktop.
Save bitkid/33bf33b8e25d8340d642d86d7c283924 to your computer and use it in GitHub Desktop.
@Serializer(forClass = ImportFormat::class)
object ImportFormatSerializer : KSerializer<ImportFormat> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("IRISerializer", PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: ImportFormat) {
encoder.encodeString(value.toString())
}
override fun deserialize(decoder: Decoder): ImportFormat {
return try {
ImportFormat.valueOf(decoder.decodeString().uppercase())
} catch (e: Exception) {
throw SerializationException(e.message)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment