Advertisement
Guest User

Untitled

a guest
Jun 26th, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.87 KB | None | 0 0
  1.         @Serializable
  2.         class FloatLong(val float: Float = .0f, val long: Long = 0L)
  3.    
  4.         object FloatLongSerializer : KSerializer<FloatLong> {
  5.             override val descriptor: SerialDescriptor = SerialDescriptor("FloatLong", UnionKind.CONTEXTUAL)
  6.             override fun deserialize(decoder: Decoder): FloatLong { TODO() }
  7.             override fun serialize(encoder: Encoder, value: FloatLong) {
  8.                 val output = encoder as? JsonOutput ?: throw SerializationException("This class can be saved only by Json")
  9.                 val j = output.json.toJson(
  10.                     JsonElementSerializer.list,
  11.                     listOf<JsonElement>(
  12.                         JsonPrimitive(value.float),
  13.                         JsonPrimitive(value.long)
  14.                     )
  15.                 )
  16.                 output.encodeJson(j)
  17.             }
  18.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement