Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Serializable
- class FloatLong(val float: Float = .0f, val long: Long = 0L)
- object FloatLongSerializer : KSerializer<FloatLong> {
- override val descriptor: SerialDescriptor = SerialDescriptor("FloatLong", UnionKind.CONTEXTUAL)
- override fun deserialize(decoder: Decoder): FloatLong { TODO() }
- override fun serialize(encoder: Encoder, value: FloatLong) {
- val output = encoder as? JsonOutput ?: throw SerializationException("This class can be saved only by Json")
- val j = output.json.toJson(
- JsonElementSerializer.list,
- listOf<JsonElement>(
- JsonPrimitive(value.float),
- JsonPrimitive(value.long)
- )
- )
- output.encodeJson(j)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement