Is there a way with reified generics to safely get...
# serialization
s
Is there a way with reified generics to safely get a
serializer
from a generic
T
at compile-time? I know about
KClass<T: Any>.serializer()
but that relies on reflection. Likely doesn’t exist, but it would be cool to be able to mark a generic reified argument as
@Serializable
too (maybe limited to
internal
or
private
so that the constraint could be validated at compile time) so the compiler can validate it’s not used improperly and also to allow compile-time optimization of the inlined code to get the Serializer companion/object that’s available.
k
Why not pass the serializer itself?
s
No specific reason, that’s how I’d do it now.
k
I think you are supposed to pass a serializer