Sam Garfinkel

    Sam Garfinkel

    2 years ago
    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.
    Kroppeb

    Kroppeb

    2 years ago
    Why not pass the serializer itself?
    Sam Garfinkel

    Sam Garfinkel

    2 years ago
    No specific reason, that’s how I’d do it now.
    Kroppeb

    Kroppeb

    2 years ago
    I think you are supposed to pass a serializer