You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is your use-case and why do you need this feature?
Delegating serializers are common feature, but it's quite boilerplatish to use. Maybe we can implement some API, which would provide shorter syntax to create them.
Describe the solution you'd like
E.g. it can be a class you can extend, like.
abstract class DelegatingKSerializer<S, T> : KSerializer<T>(val delegate: KSerializer<S>) {
override val descriptor get() = delegate.descriptor
abstract fun serialize(value: T): S
abstract fun deserialize(value: S): T
override fun serialize(encoder: Encoder, value: T) = encoder.encodeSerializableValue(delegateSerializer, serialize(value))
override fun deserialize(decoder: Decoder): S = deserialize(decoder.decodeSerializableValue(delegateSerializer))
}
Then example from tutorial would look like
class ColorIntArraySerializer : DelegatingKSerializer<Int, Color>(serializer()) {
override fun serialize(value: Color) = intArrayOf(
(value.rgb shr 16) and 0xFF,
(value.rgb shr 8) and 0xFF,
value.rgb and 0xFF
)
override fun deserialize(array: IntArray) = Color((array[0] shl 16) or (array[1] shl 8) or array[2])
}
which is significantly cleaner, than original one.
It would be also nice to avoid passing serializer() explicitly here, but I didn't come up how we can do this.
The text was updated successfully, but these errors were encountered:
What is your use-case and why do you need this feature?
Delegating serializers are common feature, but it's quite boilerplatish to use. Maybe we can implement some API, which would provide shorter syntax to create them.
Describe the solution you'd like
E.g. it can be a class you can extend, like.
Then example from tutorial would look like
which is significantly cleaner, than original one.
It would be also nice to avoid passing serializer() explicitly here, but I didn't come up how we can do this.
The text was updated successfully, but these errors were encountered: