Created
June 1, 2022 13:32
-
-
Save bitkid/33bf33b8e25d8340d642d86d7c283924 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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